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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
amaleranda
Post Patron
Post Patron

Calculate previousday total

Hi DAX gurus, 

 

I use to below fromula to calculate previous day total(Measure).

 

It does not seem to like me :(.

 

Any help would be really appriciated.

 

PreviousDayTotal :=
VAR DayPrevous = DATEADD(Targets[Date], -1, DAY)
VAR Total = SUM(Targets[Total])
VAR TotalPerviousDay=
CALCULATE(
[Total],
DayPrevous
 
)

RETURN
TotalPerviousDay

 

 

6 REPLIES 6
Anonymous
Not applicable

maybe instead of "formula does not seem to like me" show expected results and outcome, it would be easier to help you.

Anyway i'm not 100% sure you can create a measure inside a var and recalculate it again in the result.

 

Try to create a measure
TotalSum= SUM(Targets[Total])

Then a new one

PreviousDayTotal =
VAR DayPrevous = DATEADD(Targets[Date], -1, DAY)
VAR TotalPerviousDay=
CALCULATE(
[TotalSum],
DayPrevous
)
RETURN
TotalPerviousDay
 
 
 

Hi @Anonymous ,

 

Lesson learned. 🙂 thanks for the reply. 

 

I have done it that way but still not getting the result I want

 

 

DateTotalPreviousdayTotal
25-09-195000 
26-09-1960005000
27-09-1906000
28-09-1990000
29-09-1925009000
30-09-1902500

 

Previous day total is the measure I am trying to calculate.

Thanks for your time

Hi,

Create a Calendar Table and build a relationship from the Date column of your Data Table to the Date column of your Calendar Table.  To your visual, drag the Date field from the Calendar Table.  Write these measures

Total = SUM(Data[Value])

PreviousDayTotal = CALCULATE([Total],PREVIOUSDAY(Calendar[Date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi, @Ashish_Mathur 

 

I have a calander tabel and a relationship with it. 

 

I used it as you have mentioend but seems like it gives me blank values. 

 

does the format of calandar tabel date and the other tabel date has to be the same ? I have a 1* relationship with calander and my fact table.

Hi,

Both Tables should just have genuine dates.  Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur ,

 

thanks a lot for the reply, 

 

I cannot share the data with you as it is related to work.

 

But I believe I was able to sopt the issue based on the suggestion you have. 

 

My date tabel hasn't got a genuine date with year in it. That maybe the reason why. I will let you know ones I figure it out.

 

I will accept your answer as a solution if I am able to fix this based on your feedback. Thanks again.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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