cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
angryvoegi
Frequent Visitor

Value difference by Date and categorial variable

Hi all

 

I want to calculate the difference between values, based on the date as well as another categorial variable.

All that should be displayed in a waterfall diagram (column Expected Result). I attached a screenshot with dummy data and the expectet outcome.

 

Thanks in advance!

PBi Question.PNG

1 ACCEPTED SOLUTION
v-yuaj-msft
Community Support
Community Support

Hi @angryvoegi ,

 

Based on your description, you can do some steps as follows.

  1. Create a column to mark month.

 

Month = MONTH('Diff'[Date])

2.  Create a new measure.

 

Test Value =

var x1=MAXX(FILTER(ALL(Diff),[Month]=SELECTEDVALUE(Diff[Month])&&'Diff'[Cat]=SELECTEDVALUE(Diff[Cat])),'Diff'[Value])

var x2=MAXX(FILTER(ALL(Diff),[Month]=SELECTEDVALUE(Diff[Month])-1&&'Diff'[Cat]=SELECTEDVALUE(Diff[Cat])),'Diff'[Value])

return

x1-x2

 

Result:

v-yuaj-msft_0-1607301414935.png

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User III
Super User III

Hi,

Try this calculated column formula

=data[value]-lookupvalue(data[value],data[date],calculate(max(data[date]),filter(data,data[cat]=earlier(data[cat])&&data[date]<earlier(data[date]))),data[cat],data[cat])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yuaj-msft
Community Support
Community Support

Hi @angryvoegi ,

 

Based on your description, you can do some steps as follows.

  1. Create a column to mark month.

 

Month = MONTH('Diff'[Date])

2.  Create a new measure.

 

Test Value =

var x1=MAXX(FILTER(ALL(Diff),[Month]=SELECTEDVALUE(Diff[Month])&&'Diff'[Cat]=SELECTEDVALUE(Diff[Cat])),'Diff'[Value])

var x2=MAXX(FILTER(ALL(Diff),[Month]=SELECTEDVALUE(Diff[Month])-1&&'Diff'[Cat]=SELECTEDVALUE(Diff[Cat])),'Diff'[Value])

return

x1-x2

 

Result:

v-yuaj-msft_0-1607301414935.png

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi, thank you very much for your help!! It worked perfectly 🙂

Thanks again!

amitchandak
Super User IV
Super User IV

@angryvoegi , Try a new column like

new column =
var _max = maxx(filter(Table, [cat] =earlier([cat]) && [Date] <earlier([Date])),[Date])
return
[value] - maxx(filter(Table, [cat] =earlier([cat]) && [Date] =_max),[value])



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

@amitchandakThank you very much for your reply!

Unfortunately I get an error ("syntax for return is incorrect").

Thanks again 🙂

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

April Update

Check it Out!

Click here to read more about the April 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.