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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
quyen103
Frequent Visitor

DAX calculation

Hello friends,

I hope someone can help me out with this problem.  I don't know how I can implement this calculated column in PowerBI.

Should I use DAX? calculated function? data modelling? should I do this in ETL instead of Power BI?

 

Please see exhibit A below.  Smiley Happy 

I have a column (Column3) that needs to be calculated by two other columns from a previous row.  Previous row is denoted by smaller value in Column 0

Not only that, the calculated column would restart for each group of Column 0, so previous row actually gets restart whenever column 0 is 1 again.  I can add another column to denote each group of rows. (for rows with Column0 1-3)

 

Any pointers is greatly appreciated!  Thank you!

 

Column 0

Column 1

Column2

Column3 = ( Column 1 + Column 2 ) of previous row

Restart previous row value when Column 0 value is 1

3

60

600

= 50+500 = 550

2

50

500

= 40 + 400 = 440

1

40

400

 

3

30

300

= 20+200 = 220

2

20

200

= 10 + 100 = 110

1

10

100

 

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

@quyen103

Add an Index Column in the Query Editor as shown in the image below...

Then create this COLUMN

 

Column 3 =
VAR CurIndex = 'Table'[Index]
RETURN
    IF (
        'Table'[Column0] = 1,
        BLANK (),
        CALCULATE (
            SUM ( 'Table'[Column1] ) + SUM ( 'Table'[Column2] ),
            FILTER ( 'Table', 'Table'[Index] = CurIndex + 1 )
        )
    )

 

VAR - DAX Calculation.gif

 

Hope this helps! Smiley Happy

View solution in original post

3 REPLIES 3
Sean
Community Champion
Community Champion

@quyen103

Add an Index Column in the Query Editor as shown in the image below...

Then create this COLUMN

 

Column 3 =
VAR CurIndex = 'Table'[Index]
RETURN
    IF (
        'Table'[Column0] = 1,
        BLANK (),
        CALCULATE (
            SUM ( 'Table'[Column1] ) + SUM ( 'Table'[Column2] ),
            FILTER ( 'Table', 'Table'[Index] = CurIndex + 1 )
        )
    )

 

VAR - DAX Calculation.gif

 

Hope this helps! Smiley Happy

quyen103
Frequent Visitor

Sean,

 

Thank you so much my friend, super contributor Sean 🙂

I really appreciate the video and code response.  Can't get any clearer than this.. !!

Hi @quyen103,

Please mark the right reply as answer. which will help more people to find solution.

Best Regards,
Angelia

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.