Forum Discussion
Calculate difference from value in same column and based on data from another
Hi POWER BI Team,
I need your help and I will try my best to be clear.
My dataset has three main column CLIENT, DATE (Text) and ORDER(Numeric). When I drop the column into a MATRIX, this is what I obtain:
Using DAY as a filter, I will be comparing a DAY at a time to TODAY. I would like to be able to calculate the difference and the difference % in ORDER between Today Value and Monday Value and for the measure to update when I select any other day of the week. I will always be comparing any DAY with TODAY.
Here the desired outcome:
Is there any way I can achieve this using DAX maybe? If yes, can someone help me reach the desired outcome?
Thank you in advance.
3 Replies
- amitchandakSuper User
corange , Can you share sample data and sample output in table format?
see if these two can bring some help
Power BI — WTD Questions— Time Intelligence 4–5
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
Power BI — Day Intelligence Questions — Time Intelligence 5–5
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c3243d1f9- corangePost Patron
Hi amitchandak ,
Here my sample: https://1drv.ms/u/s!AiS7XVNuQsBCbslVeWs3M66_7po?e=C3CSAB
Here a table of what i would like to achieve:
Row Labels Monday Today Difference % Row Labels Tuesday Today Difference % Client 1 1 -1 -100% Client 1 1 -1 -100% Client 13 1 1 0 0% Client 11 4 -4 -100% Client 15 1 -1 -100% Client 13 1 1 0 0% Client 3 1 -1 -100% Client 14 1 -1 -100% Client 4 4 -4 -100% Client 2 1 -1 -100% Client 5 1.25 2 0.75 60% Client 4 2.25 -2.25 -100% Client 7 2.67 5.00 2.33 87% Client 5 2 2 0 0% Client 8 1 -1 -100% Client 6 1 -1 -100% Client 9 1 -1 -100% Client 7 1 5 4 400% Client 8 2 -2 -100% - v-lili6-msftCommunity Support
hi corange
Try this way as below:
Step1:
Add a BookingDayNo column in the table.
Step2:
Create two measure as below:
Difference = var _firstday=CALCULATE(MIN('Table'[BookingDayNo]),ALLSELECTED('Table')) var _lastday=CALCULATE(MAX('Table'[BookingDayNo]),ALLSELECTED('Table')) return CALCULATE(SUM('Table'[OrderNumber]),FILTER(ALL('Table'[BookingDayName],'Table'[BookingDayNo]),'Table'[BookingDayNo]=_lastday))-CALCULATE(SUM('Table'[OrderNumber]),FILTER(ALL('Table'[BookingDayName],'Table'[BookingDayNo]),'Table'[BookingDayNo]=_firstday)) % = var _firstday=CALCULATE(MIN('Table'[BookingDayNo]),ALLSELECTED('Table')) var _lastday=CALCULATE(MAX('Table'[BookingDayNo]),ALLSELECTED('Table')) return DIVIDE(CALCULATE(SUM('Table'[OrderNumber]),FILTER(ALL('Table'[BookingDayName],'Table'[BookingDayNo]),'Table'[BookingDayNo]=_lastday))-CALCULATE(SUM('Table'[OrderNumber]),FILTER(ALL('Table'[BookingDayName],'Table'[BookingDayNo]),'Table'[BookingDayNo]=_firstday)),CALCULATE(SUM('Table'[OrderNumber]),FILTER(ALL('Table'[BookingDayName],'Table'[BookingDayNo]),'Table'[BookingDayNo]=_firstday)))Result:
By the way, it could not achieve that add custom column in the end of matrix visual, so you'd better put them in two visuals
Regards,
Lin