cancel
Showing results for
Did you mean:
New Member

Calculation with LookupValue to determine if greater than previous period value

Good Afternoon Everybody,

I am hoping that you can assist with a calculation error I am having. I am attempting to create a new column which will show

"↑","↓" depending on whether the current value is higher or lower than the previous value.  This table has multiple items in one table and it would need to look up the previous value while ensuring that the BU field and the FLEET column values are the same. I do have a date table which is called Calendar.

Does anybody have any ideas on how to do this? I've done this in other tables but never where multiple items are in the same table.

Thank you for the help in advance!

1 ACCEPTED SOLUTION
Community Champion

Hello @apowerbiguy ,

I'm not sure if I fully understood the requirements. I am checking for the value from the last quarter with identical BU and identical Fleet. Is that right?
I am just assuming the table is called MyTable. Try the following approach:

``````Previous =
VAR rowBU       = MyTable[Bu]
VAR rowFleet    = MyTable[Fleet]
VAR lastQuarter = DATEADD( MyTable[Date], -1, QUARTER )
VAR FilteredTable =
FILTER(
MyTable,
MyTable[Bu] = rowBU
&& MyTable[Fleet] = rowFleet
&& MyTable[Date] = lastQuarter
)
VAR AvailabilitytPQ = SUMX( FilteredTable, MyTable[Availability] )
RETURN
IF( MyTable[Availability] >= AvailabilitytPQ, "↑", "↓" )``````

If you need any help please let me know.
If I answered your question I would be happy if you could give it a thumbs up 👍!

Best regards
Denis

3 REPLIES 3
Community Champion

Hey @apowerbiguy ,

sure, VAR is just a variable and the result is always saved in the filtercontext when the variable is set. This I used to get the current context. The following video is explaining that:

Also check the article from SQLBI:

https://www.sqlbi.com/articles/variables-in-dax/

Best regards
Denis

Community Champion

Hello @apowerbiguy ,

I'm not sure if I fully understood the requirements. I am checking for the value from the last quarter with identical BU and identical Fleet. Is that right?
I am just assuming the table is called MyTable. Try the following approach:

``````Previous =
VAR rowBU       = MyTable[Bu]
VAR rowFleet    = MyTable[Fleet]
VAR lastQuarter = DATEADD( MyTable[Date], -1, QUARTER )
VAR FilteredTable =
FILTER(
MyTable,
MyTable[Bu] = rowBU
&& MyTable[Fleet] = rowFleet
&& MyTable[Date] = lastQuarter
)
VAR AvailabilitytPQ = SUMX( FilteredTable, MyTable[Availability] )
RETURN
IF( MyTable[Availability] >= AvailabilitytPQ, "↑", "↓" )``````

If you need any help please let me know.
If I answered your question I would be happy if you could give it a thumbs up 👍!

Best regards
Denis

New Member

Thank you again for the help!

Announcements