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
Anonymous
Not applicable

DAX show data from previous period

Hello guys,

 

I've been working with differents measures and I am still stuck.... That's why I wanna ask you guys.

 

I'm currently working in Slicer where I already have pre-defined the dates (ex: 16/03/2020, 23/03/2020, etc. (7 days difference)) and my idea is to show data from the previous date. The main issues come from when I need to include DAX in my measures. An example of one measure:

 

Mails =
CALCULATE(
SUM(XXX[Value]);Filter ('XXX';'XXX'[Indicators] IN {"Managed mails"; "Deleted Mails"}))

 

My idea is including the previous measure with some DAX which shows me the date from the previous period and not the one which I selected on the Slicer.

 

Any idea of how to carry out with this? 

 

Many thanks,

6 REPLIES 6
kentyler
Solution Sage
Solution Sage

One approach would be to use a Date or Calendar table and have one the columns be the "offset" date, so you would not have to calculate it, you could just use it as an attribute of the selected date.
so the "offset" date for  16/03/2020 would be 23/03/2020, 
then in any DAX measure where you might use the selected date, you can just substitute using the offset date

 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Anonymous
Not applicable

The issue comes when I have to include that "approach" into my measures. That's why I set an example with one of my created measures. And I truly prefer to include the solution in a Card insted of a table. Any idea?

 

Thanks,

I do not see where your sample measure makes any reference to the selected date from the slicer. Does the slicer filter the data you are using in your calcuate() ?  If so you would set up the slicer to display the date the user wants to select, but to filter by the "offset" date.

 

I don't understand your questions about using a card to display results... if the measure returns a count you can display it on a card.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Anonymous
Not applicable

Sorry, I am quite new in DAX so I may not be clear in my question, I am gonna try to explain it in a understandable way: 

 

1- As shown in the following date, that's my excel, so my idea is to sum all the numbers of a certaing indicator and date. So one if a want to see X1 indicator, show me the total number (sum 1+1+1 = 3). With dates row I changed it to unpivot table to make an slicer (so if I choose one date in the slicer it filters the measures created). 

 Week
Indicator16-03-2023-03-2030-03-2006-04-20
X1111 
X2 2 5
X31   

 

Attribute.png

 

 

2-  I created many measures to carry out my idea:  

Mails =
CALCULATE(
SUM(XXX[Value]);Filter ('XXX';'XXX'[Indicators] IN {"X1"; "X2"}))
 
That's works very well, there's no issues. So my next step is to show my previous data, so if i select on the slicer 23-03-2020, the measure (or whatever) has to show me the previous data.
 
I don't know if I am clear with my issue. If it's so, there's any way to do it with cards? Or maybe using tables?
 
Many thanks for you time and effort!

Hi,

You should have a Calendar Table with a relationship from the Attribute column of XXX table to the Date column of the Calendar Table.  Your slicer should be build from the Date column of the Calendar Table.  Write this measure

=CALCULATE([Mails],DATESBETWEEN(Calendar[Date],MIN(Calendar[Date])-7,MIN(Calendar[Date])-7))

Hope this helps.


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

 

 

// It's actually very easy to do what you want
// but only on condition your model is built
// correctly. Calendar table must be THE
// date table in the model connected to your
// fact table. The days that belong to one
// week should have a column next to them with the date
// of the first day of the week. This should be
// named something like [Week Start]. These week starts
// should be in your slicer as well.

[Mails PW] = // mails previous week
var __oneWeekVisible = HASONEVALUE( 'Calendar'[Week Start] )
var __dayLag = 7 // back one week
var __result =
	CALCULATE(
		[Mails],
		DATEADD(
			'Calendar'[Date],
			-__dayLag,
			DAY
		)
	)
return
	if( __oneWeekVisible, __result )

 

 

 

Best

D

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.