Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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

  • 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.

     

     

    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

2 Replies

  • 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.

     

     

    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

  • 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"
    )
    )