Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
apowerbiguy
Regular Visitor

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!
 

 

 

powerbi question.png

 

 

 

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

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

View solution in original post

3 REPLIES 3
selimovd
Super User
Super User

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:
https://www.youtube.com/watch?v=71ERlpfhmwU


Also check the article from SQLBI:

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

 

Best regards
Denis

selimovd
Super User
Super User

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

Thank you! This is perfect and worked, I am looking to learn more about VAr do you have any recommendations for where to learn more?

 

Thank you again for the help!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.