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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
Anonymous
Not applicable

how to calculate Y(n)=X(n)+Y(n-1) in DAX?

Hello! I have a measure X, and also a calculated column N. 

N    X

1    0.9

2    0.8

3     0.7

4    0.8

.....

I need to calculate a measure Y, so that Y(n)=X(n)+Y(n-1) 

so that 
N  X   Y

1 0.9   0.9
2 0.8   1.7

3  0.7   2.4

.....

In this case , N is a calculated column , X is a measure I calculated, how to calculate Y?  Thank you in advance!

3 ACCEPTED SOLUTIONS
Mikelytics
Resident Rockstar
Resident Rockstar

Hi DuoHappy,

 

I did it with a date tables as an example

 

in my case N=date of date table (column)

X= a Measure which counts the days 

Y = the measure which calculates the running total based on the date

Mikelytics_0-1666776125623.png

 

 

Y = 
CALCULATE(
    [X (Count of Days)],
    FILTER(ALL('Dim Date'),
        'Dim Date'[Date] <= MAX('Dim Date'[Date])
    )
)

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

Did you try this?

 

Y = 
CALCULATE(
    [X],
    FILTER(ALL('Table where N is stored'),
        'Table where N is stored'[N] <= MAX('Table where N is stored'[N])
    )
)

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could try it.

Measure = SUMX(FILTER(ALL('Table'),[No]<=MAX('Table'[No])),[X])

The final show:

vyalanwumsft_0-1666854985198.png

If the above one can't help you get the desired result, please provide a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community
Best Regards,
Community Support Team _ Yalan Wu
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

13 REPLIES 13
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could try it.

Measure = SUMX(FILTER(ALL('Table'),[No]<=MAX('Table'[No])),[X])

The final show:

vyalanwumsft_0-1666854985198.png

If the above one can't help you get the desired result, please provide a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Mikelytics
Resident Rockstar
Resident Rockstar

Hi DuoHappy,

 

I did it with a date tables as an example

 

in my case N=date of date table (column)

X= a Measure which counts the days 

Y = the measure which calculates the running total based on the date

Mikelytics_0-1666776125623.png

 

 

Y = 
CALCULATE(
    [X (Count of Days)],
    FILTER(ALL('Dim Date'),
        'Dim Date'[Date] <= MAX('Dim Date'[Date])
    )
)

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
Anonymous
Not applicable

In your case, NO. is from dim date, but in my case No. is a calculated column from Fact table, which has multiple values.

Hi DuoHappy,

 

It doesn't matter. It also works with duplicates thanks to the MAX() function.

 

Best regards

Michael

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

Did you try this?

 

Y = 
CALCULATE(
    [X],
    FILTER(ALL('Table where N is stored'),
        'Table where N is stored'[N] <= MAX('Table where N is stored'[N])
    )
)

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
Anonymous
Not applicable

DuoHappy_0-1666778055705.pngsorry, it is not working in my case

 

ah okay,

 

is there a multiplication in your x measure going? If yes you have to sorround my solutuion with a SUMX

 

Y = 
SUMX(
VALUES('Table of N'[N]),
CALCULATE(
    [X],
    FILTER(ALL('Table where N is stored'),
        'Table where N is stored'[N] <= MAX('Table where N is stored'[N])
    )
)
)
------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
Anonymous
Not applicable

Hello! I thought I can not using your suggestion to get the right answer. This might because in my calculation of X, I also used all function in the formula. and now Y if using all function again, which caused problem so that this value is not correct

Anonymous
Not applicable

Hello! Thanks ! I am thinking Y= 

CALCULATE(
    sum([X]),
    FILTER(ALL('Table where N is stored'),
        'Table where N is stored'[N] <= MAX('Table where N is stored'[N])
    )
)

but it is wrong.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

Jihwan_Kim_0-1666775895607.png

 

 

Expected result measure: =
[Sales measure:]
    + CALCULATE ( [Sales measure:], Data[Index CC] <= MAX ( Data[Index CC] ) - 1 )

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Hi, using you syntax can not get the value you showed, please see. Could you please give more guidance?

DuoHappy_1-1666780179174.png

 

Hi,

Please share your sample pbix file's link here, and then I can try to look into it.

Thanks.

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

VijayP
Super User
Super User

@Anonymous 

in the above case is actually a multiplication of column wiht measure is that right?
then in the data view along with N , add another column with  X = X measure , it gives you the value of measure as a column in the table

Then you can use sumx(table, n*x) will give youthe value as requried! 




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.