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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ph
Helper I
Helper I

ONLY FOR PBIX, DAX MASTERS! :) -> sum previous row value + current row value and merge it

Hi all,

 

I have table with following values

 

DateDocument typeAmount
01.01.2019110
02.01.2019220
03.01.2019330
06.01.2019410
09.01.2019220
12.01.2019330

 

Each document type has some spaces in date (4,5,7,8,10,11 etc.. of Jan 2019 is missing, that's correct), but dimension DATE contains all values in year on each row, but document types not..

I need to merge document types with each day in year for document type (1,2,3) and count previous value with current of the result of the day.. result should be this:

DateAmount
01.01.201910
02.01.201930
03.01.201960
04.01.201960
05.01.201960
06.01.201960
07.01.201960
08.01.201960
09.01.201980
10.01.201980
11.01.201980
12.01.2019110

 

I created calculated column in dimension DATE (because it contains all values), but I don know how to do SUM of previous row with current ROW...I created a measure where I sum all document types
(Total Amount= Measure 1 + Measure 2 +Measure 3)
         where
         Measure 1=

         CALCULATE(SUMX(Document; [Amount]);'Document Type'[Document Type]=1)

         
         Measure 2=

         CALCULATE(SUMX(Document; [Amount]);'Document Type'[Document Type]=2)
         
         Measure 3=
         CALCULATE(SUMX(Document; [Amount]);'Document Type'[Document Type]=3)


         and I tried used 'earlier' in function in column
         Total Amount=Total Amount+earlier(Total Amount)

         ,but it does not works

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The OriginalData table is what you should import from your data source. The other tables were created using OriginalData as the source.

OriginalData should have columns Date, DocType, Amount. In truth, they could have any names. It's just a matter of adjusting the names in the M code.

The thing is you should first import your Original Data and then create the Calendar as I have in the file and then create the ProcessedData table that uses both: the Calendar and OriginalData.

All the steps are there in the M code.

 

If you import your table into the file I gave you, delete the OriginalData and rename your imported table to OriginalData (and the columns will be the same with the same names as the table you've just deleted) the other tables will be there ready for you to use immediately.

Best
D.

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Use Power Query for this. DAX is not the right tool for this kind of job. But if you like squeezing a square peg into a round hole... then DAX is the way to go 🙂

Best
Darek

@Anonymous OK..but my question is the same...how to do it?
in power query I don t see any measures etc..


Anonymous
Not applicable

Hi @Anonymous

 

many thanks for solution! It is what I need it..but is it possible to write here any comments? I want to implemented to my report and absolutely no idea how and what you set up..I see that steps on the right side, but it is very high level

Anonymous
Not applicable

The OriginalData table is what you should import from your data source. The other tables were created using OriginalData as the source.

OriginalData should have columns Date, DocType, Amount. In truth, they could have any names. It's just a matter of adjusting the names in the M code.

The thing is you should first import your Original Data and then create the Calendar as I have in the file and then create the ProcessedData table that uses both: the Calendar and OriginalData.

All the steps are there in the M code.

 

If you import your table into the file I gave you, delete the OriginalData and rename your imported table to OriginalData (and the columns will be the same with the same names as the table you've just deleted) the other tables will be there ready for you to use immediately.

Best
D.

@Anonymous 

thanks for it

I also found an article how to do it in DAX and its works (https://joyfulcraftsmen.com/blog/dax---cumulative-total-and-blank-handling/)

🙂

Anonymous
Not applicable

Good advice: you should never do in DAX what you can do in Power Query if you want your model to run at the peak speed. Columns calculated in DAX are never compressed as well as the ones that come from Power Query. And compression plays a big role when the storage engine is calculating things for you in DAX.

Best
D.
Anonymous
Not applicable

Bear with me a sec... I'm creating a solution. By the way, this stuff is best done in Power Query, not in DAX.

Best
D.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

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.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.