DAX to multiply two max date measures - matrix

I am fairly new to Power BI and was hoping to solve my total (multiplication problem).
I have running inventory table for supplies ordered. I need to have a breakdown of the cost of those supplies based on the last item ordered(prices constantly change). I have two measures, one for the latest cost, and the second for the latest units used.
Latest Unit/Cost =
VAR maxdate = MAX(InventoryJ[Date Ordered])
RETURN
CALCULATE(SUM(InventoryJ[Cost/Unit]),
InventoryJ[Date Ordered]=maxdate)
and
Latest UnitsUsed =
VAR maxdate = MAX(InventoryJ[Date Ordered])
RETURN
CALCULATE(SUM(InventoryJ[Unit Used]),
InventoryJ[Date Ordered]=maxdate)
In my matrix they work great, even though the total is incorrect in the table.
Now I am stuck on multiplying these two measures together for the latest units used and the latest cost per unit.
Best Regards

Latest Total Cost = [Latest Unit/Cost] * [Latest UnitsUsed]
Consider using this kind of test to fix your total row.
If ( HasOneValue ( InventoryType[Summary]), ...
Then put whatever high level aggreation you want into the FALSE condition of that IF statement.

Related

Dynamic Calculated Column on different report level SSAS DAX query

I'm trying to create a calculated column based on a derived measure in SSAS cube, this measure which will count the number of cases per order so for one order if it has 3 cases it will have the value 3.
Now I'm trying to create a bucket attribute which says 1caseOrder,2caseOrder,3caseOrder,3+caseOrder. I tried the below one
IF([nrofcase] = 1, "nrofcase[1]", IF([nrofcase] = 2, "nrofcase[2]",
IF([nrofcase] = 3, "nrofcase[3]", "nrofcase[>3]") )
But it doesn't work as expected, when the level of the report is changed from qtr to week it was suppose to recalculate on different level.
Please let me know if it case work.
Calculated columns are static. When the column is added and when the table is processed, the value is calculated and stored. The only way for the value to change is to reprocess the model. If the formula refers to a DAX measure, it will use the measure without any of the context from the report (eg. no row filters or slicers, etc.).
Think of it this way:
Calculated column is a fact about a row that doesn't change. It is known just by looking at a single row. An example of this is Cost = [Quantity] * [Unit Price]. Cost never changes and is known by looking at the Quantity and Unit Price columns. It doesn't matter what filters or context are in the report. Cost doesn't change.
A measure is a fact about a table. You have to look at multiple rows to calculate its value. An example is Total Cost = SUM(Sales[Cost]). You want this value to change depending on the context of time, region, product, etc., so it's value is not stored but calculated dynamically in the report.
It sounds like for your data, there are multiple rows that tell you the number of cases per order, so this is a measure. Use a measure instead of a calculated column.

Power BI Matrix Totals calculating incorrectly for

I am currently having an issue with the power bi Matrix Calculation when using dax. I need to calculate the Running total for overtime per fortnight, which I have achieved using the following
Lieu running total to Date = CALCULATE(SUM('Table1'[OT]),FILTER(ALLSELECTED('Calendar'[Date]),ISONORAFTER('Calendar'[Date], MAX('Calendar'[Date]), DESC)))
However I now need to calculate the excess hours (OT) which I have used the following to calculate people over 90 hours(additional 10 hours)
Excess Lieu2 = IF([Lieu running total in Date]>=160,[Lieu running total in Date]-160,0)
The issues is the the grand totals is calculating the entire total - 160
The the last few total rows as well as the grand total are aggregating incorrectly...ANy help is greatly appreciated. A Dax solution is needed as this will need to be dynamic as the employees names will be added
Add a new measure with below code and add that measure to your matrix.
Total_Lieu_running_total_to_Date =
SUMX (
SUMMARIZE (
table,//add the table from which the pay period end date is coming
table[pay period end date],//date column which you are using in matrix
"Lieu_running_total_to_Date",
[Lieu running total to Date] //measure which you using currently
),
[Lieu_running_total_to_Date]
)
Note:- Please add some sample data so it would help other to give you solution quickly.

DAX accounting calculations with dates and amounts in Power BI

I am completely new to DAX and therefore still deep in the process of understanding the logics of this language.
I have a dataset containing of the columns: dates, amounts, events indices, balances and days.
I want to obtain two things:
- the balance at the start of each month
- the difference between all positive and negative amounts (so having the sum of one and the other,
for convenience)
I believe that a Measure if the way to go to get both quantities.
For the first I thought of creating a new column (just to readily
visualise the result of my tentative formula).
I came up with the following:
Column = IF(
ListaMovimenti[Index]=1,
ListaMovimenti[Amount],
IF(
AND(
ListaMovimenti[Day]=1,
LOOKUPVALUE(ListaMovimenti[Day],ListaMovimenti[Index],ListaMovimenti[Index]+1) <> 1
),
LOOKUPVALUE(ListaMovimenti[Balance], ListaMovimenti[Index], ListaMovimenti[Index]-1),
0
)
)
This (clearly) works only partially, as shown below
when the formula finds a new month entry not starting with 1, this breaks down.
For the second task, as well as the first one, I thought of invoking some date handling function.
I feel like implementing some loop when evaluating the measure, but I read that it's not easy to implement them in DAX.
UPDATE
I managed the first part using the following code
Column = IF(
ListaMovimenti[Index]=1,
ListaMovimenti[Amount],
IF(
MONTH(ListaMovimenti[Date]) <> MONTH(LOOKUPVALUE(ListaMovimenti[Date],ListaMovimenti[Index],ListaMovimenti[Index]-1)),
LOOKUPVALUE(ListaMovimenti[Balance], ListaMovimenti[Index], ListaMovimenti[Index]-1),
0
)
)
However, I'm now struggling to turn this into a Measure as I can't call
the columns into measures.
I also haven't yet figured out the second part:
getting per-month sum of positive and negative amounts.
I'm having a really hard time figuring the logic of this one-line language syntax,
so any help is hugely appreciated. Thanks

Creating a variance column for financials in DAX (credits/debits) with the correct sign

I have revenue data that has a natural credit balance (less than zero or negative) and expense data that has a natural debit balance (greater than zero or positive). Revenue accounts are tagged as reporting code=400 and all other items are some other number other than 400.
I would like to create a variance column between two measures where the idea is to display whether it is favorable to profit or not. Creating the two measures is not the problem...it is that the variance calculation itself is different for revenue than expenses. Current-LastPeriod=Variance will work for Revenue, while (Current-LastPeriod)*-1=Variance will work for Expenses.
How can I construct a DAX calculation that handles this type of situation?
I tried IF statements but received an error saying a single value for my reportingcodeid column could not be determined. It makes sense as it is a measure. Here is what I tried.
Variance:=IF(TrialBalance_View[ReportingCode1ID]=400,[MonthlyAmount]-[MonthlyAmount_PY],[MonthlyAmount]-[MonthlyAmount_PY]*-1)
This is an issue I am sure a lot of Finance/Accounting people have and I appreciate any help I can get! Thank you!!
Without seeing your data model and code of the measures, I suggest this approach:
Variance =
SUMX(
VALUES(TrialBalance_View[ReportingCode1ID]),
VAR Account_Variance = [MonthlyAmount]-[MonthlyAmount_PY]
RETURN IF(TrialBalance_View[ReportingCode1ID] = 400, Account_Variance, -Account_Variance)
)
Here, we first create a list of reporting codes visible in a current context using VALUES function. Then, SUMX iterates these codes one by one. For each code, it computes variance and stores it in a variable. Then, if code is 400, it takes variance, else it takes negative variance.
If it does not work, please add your data model diagram, and post DAX code for your measures.

Rating System with Elo, better alternatives?

I'm working on a rating algorithm. I have a set of exercises. They are all categorized in levels (1 = easiest, 5 = hardest).
Users get shown two exercises and should decide which one is harder or if both are equal. Based on user ratings, the levels should get adjusted.
What I've done:
I experimented with the Elo rating.
My Questions:
Are there any better algorithms for doing this use case? (found nothing so far)
Thanks in advance and cheers.
Toby
I would try to solve the problem in a simple yet (I hope) effective way.
First, you only update an exercise rating when the vote is different that what the system actually expects. From now on, I will only considers the cases where the user output differs from what the system actually expects.
Second, I would give more weight to the votes where the two levels have a big difference. A wrong expectation on two esercises with rating 2 and 3 should have less impact than a wrong expectation on two exercises with rating 1 and 5.
That said, my algorithm would be along the lines of:
1- A constant percentage is set, let's call it increment. It establishes the percentage of impact that a vote has, and can be modified along the way based on the number of users.
2- For an "unexpected" vote, I would calculate the difference between the original levels (minimum of 1).
diff = max(1, abs(ex1.level - ex2.level))
3- I would update each exercise rating by a percentage, based on the multiplication of increment and diff.
if (ex1 level expected bigger)
ex1.rating = ex1.rating + diff*increment;
else
ex1.rating = ex1.rating - diff*increment;
Rating would be a float, and level would be the rounding of rating:
ex1.level = round(ex1.rating)
Example:
let's set increment = 0.1. exA, with a rating of 2.0 and level 2 is compared with exB, rating of 3.0 and level 3.
The first user selects exB as the hardest. Nothing changes, because it is the result expected by the system.
The second user selects exA. It is not the expected result. The difference between the two exercises is 1, so the rating is modified by a factor 1*0.1 = 0.1,
resulting in a exA.rating = 2.1 for exB.rating = 2.9

Resources