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
Anonymous
Not applicable

Need help with DAX

Hello Experts,

 

I have a table as mentioned below:

 

DateFieldValueCategory
01-01-20201A
02-01-202010A
03-01-2020100A
04-01-2020100A
03-01-2020100B
04-01-2020100B

 

I want to plot accumulated values on a graph. The catch here is, if i select a period of 01-Jan-2020 to 04-Jan-2021 and plot two lines for Categories A and B, the value of the first datapoint(one with minimum date) for each category should be subtracted from each and every data point(including the first point; thus making it zero). The dax mentioned below gives me the result when i browse the values by category:

 

Cumulative value =
CALCULATE(
SUM('MyTable'[Value]),
FILTER(
ALLSELECTED('MyTable'[DateField]) ,
ISONORAFTER('MyTable'[DateField], MAX('MyTable'[DateField]), DESC)
)
)

-

CALCULATE(SUM('MyTable'[Value])
,FILTER(ALLSELECTED('MyTable'[DateField]), 'MyTable'[DateField] = CALCULATE(MIN('MyTable'[DateField]),ALLSELECTED('MyTable'[DateField]))))

 

Although, this measure does not work when i try to browse the value at an overall level and not by category.

I could group it by category to get the sum of the values, but subtracting first value for each group is where i am stuck at.

 

Asking you experts for your help.

 

Kind Regards,

Chetan

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please check the below picture and the sample pbix file's link, whether it is what you are looking for.

All measures are in the sample pbix file, and all steps are numbered in front of each measure.

 

Picture1.png

 

https://www.dropbox.com/s/fabheo5e695rgij/chetanam.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please check the below picture and the sample pbix file's link, whether it is what you are looking for.

All measures are in the sample pbix file, and all steps are numbered in front of each measure.

 

Picture1.png

 

https://www.dropbox.com/s/fabheo5e695rgij/chetanam.pbix?dl=0 

 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@Anonymous , Not sure, I got it completely. Based on what I got Try like

 

Cumulative value =
CALCULATE(
SUM('MyTable'[Value]),
FILTER(
ALLSELECTED('MyTable'[DateField]) ,
ISONORAFTER('MyTable'[DateField], MAX('MyTable'[DateField]), DESC) && 'MyTable'[Category] ="A"
)
)

-

CALCULATE(
SUM('MyTable'[Value]),
FILTER(
ALLSELECTED('MyTable'[DateField]) ,
ISONORAFTER('MyTable'[DateField], MAX('MyTable'[DateField]), DESC) && 'MyTable'[Category] ="B"
)
)

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.