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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
trotsale
Regular Visitor

Calculating difference between rows by date

Hello!

 

I have a problem and here it is:

 

In my Power Bi I have a table with report which is getting data from local folder. A key is date, which is adding as a column on every refresh. It looks like this: Capture.PNG

 I already have a measure which counts number of devices by date, it seems like

DevicesByDate = CALCULATE(COUNTROWS('Table');DISTINCT('Table'[Date]))

But I can`t get a measure which will substract number of DevicesByDate from previous date (Example: 4 devices by 08/15/2017-4 devices by 07/21/2017 = 0). 

 

Can you please help me guys?

Thanks!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @trotsale

 

Try out this method. This method grabs the device ids from last month and subtracts them from device ids this month.

 

DevicesByDate difference last month compared to this month = CALCULATE(COUNTROWS('Test');DISTINCT('Test'[Date]);DATEADD(DATESBETWEEN(Test[Date];STARTOFMONTH(Test[Date]);ENDOFMONTH(Test[Date]));-1;MONTH)) - CALCULATE(COUNTROWS('Test');DISTINCT('Test'[Date]);DATESINPERIOD(Test[Date];LASTDATE(Test[Date]);-1;MONTH)) 

 

Best,

Martin

View solution in original post

5 REPLIES 5
GilbertQ
Super User
Super User

Off the top of my head have you tried another calculation which would use the PREVIOUSDAY DAX function?

Devices Previous Day = CALCULATE([Devices],PREVIOUSDAY('Date Table'[Date]))

You would need to have a Date table in order for this to work. I think it might look for the Previous Day being 08/14/2017 though.




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Anonymous
Not applicable

Hi @trotsale

 

Try out this method. This method grabs the device ids from last month and subtracts them from device ids this month.

 

DevicesByDate difference last month compared to this month = CALCULATE(COUNTROWS('Test');DISTINCT('Test'[Date]);DATEADD(DATESBETWEEN(Test[Date];STARTOFMONTH(Test[Date]);ENDOFMONTH(Test[Date]));-1;MONTH)) - CALCULATE(COUNTROWS('Test');DISTINCT('Test'[Date]);DATESINPERIOD(Test[Date];LASTDATE(Test[Date]);-1;MONTH)) 

 

Best,

Martin

Anonymous
Not applicable

@trotsale Did it work out for you?

Thank you so much for help! 

It works now, but it displays uptake only when graphic is shown by quarter or year. When I choose display by month, It shows me number of devices. Maybe I should change dates period?By yearBy year

 

 

By monthBy month

 

 

I`ve tried this and here is what i got:

graphics.PNG

 

 Here is the way I used DAX: dax.PNG

 

 My DateTable consists of 2 dates (07/21/2017 and 08/14/2017). Am I doing something wrong?

 

 

 

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors