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
monojchakrab
Resolver III
Resolver III

use selectedvalue to reflect MTD sales for previous month

Hi Good people,

 

I am struggling a bit with the dashboard as below :

 

Screenshot (123).png

What I want to achieve is as follows :

When I choose the date from the date slicer (this is a disconnected table), it should return me the two pies and the two tables below that - one each for the current month and the previous month.

I am achieving the display for the current and M-1 graph and table by using a flag (whch goes as a filter on the visual) as below :

Flag_previous = 
var _Selectmonth = MONTH(SELECTEDVALUE('Date slicer'[Date]))
return
if (MONTH(MAX('Amazon YTD'[Purchase Date]))=_Selectmonth-1,1,0)

While the flag currently displays the months, for the previous month, the data shown is for the full month and not till the day chosen from the date slicer.

Can this be fixed, by modifying the MTD-1 measure I am using, whereby it computed MTD only till the day chosen :

MTD Val = 

    TOTALMTD('Measures tray'[Total Sales],'Date Table'[Date])

Thanks

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@monojchakrab , try like

 

MTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LMTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = date(Year(_max1), month(_max1)-1, day(_max))
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LMTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

var _max = date(year(today()),month(today())-1,day(today())-1)
var _min = eomonth(_max,-1)+1
return
CALCULATE(sum['amazon',[purchase date] ,DATESBETWEEN('calendar'[Date],_min,_max))

Hii @monojchakrab 

 

please use this dax, I re-write this code from @amitchandak 

 

Anonymous
Not applicable

var _max = date(year(today()),month(today())-1,day(today())-1)
var _min = eomonth(_max,-1)+1
return
CALCULATE(sum['amazon',[purchase date] ,DATESBETWEEN('calendar'[Date],_min,_max))

Hii @monojchakrab 

 

please use this dax, I re-write this code from @amitchandak 

 

amitchandak
Super User
Super User

@monojchakrab , try like

 

MTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LMTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = date(Year(_max1), month(_max1)-1, day(_max))
var _min = eomonth(_max1,-2)+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

LMTD QTY forced=
var _max = date(year(today()),month(today())-1,day(today()))
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESMTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALMTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

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.