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

Period DAX Measure

Hi Experts

 

I have created a discount table in order to work out the following measure....in order to work out sales....for the following periods

 

Daily, Week, Monthly and Yearly and all Date 

 

not sure how to write the measure - help please...

 

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.


View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

1. Enter data table.

vyalanwumsft_0-1642742446150.png

2.create a measure.

Every-sales = 
var _year=CALCULATE(SUM([sales]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date]))))
var _month=CALCULATE(SUM([sales]),FILTER(ALL('Table'),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0)))
var _week=CALCULATE(SUM([sales]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date]))&&WEEKNUM([Date],2)=WEEKNUM(MAX([Date]),2)))

return
SWITCH(MAX('slicer'[slicer]),
"daily",SUM('Table'[sales]),
"Weekly",IF(WEEKDAY(MAX([Date]),2)=1,_week),
"month",IF(MAX([Date])=CALCULATE(MIN([Date]),FILTER(ALL('Table'),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0))),_month),
"year",IF(MAX([Date])=CALCULATE(MIN([Date]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date])))),_year),
"total",SUMX(ALL('Table'),[sales]))

The final output is shown below:

vyalanwumsft_1-1642742502515.pngvyalanwumsft_2-1642742511063.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

1. Enter data table.

vyalanwumsft_0-1642742446150.png

2.create a measure.

Every-sales = 
var _year=CALCULATE(SUM([sales]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date]))))
var _month=CALCULATE(SUM([sales]),FILTER(ALL('Table'),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0)))
var _week=CALCULATE(SUM([sales]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date]))&&WEEKNUM([Date],2)=WEEKNUM(MAX([Date]),2)))

return
SWITCH(MAX('slicer'[slicer]),
"daily",SUM('Table'[sales]),
"Weekly",IF(WEEKDAY(MAX([Date]),2)=1,_week),
"month",IF(MAX([Date])=CALCULATE(MIN([Date]),FILTER(ALL('Table'),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0))),_month),
"year",IF(MAX([Date])=CALCULATE(MIN([Date]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date])))),_year),
"total",SUMX(ALL('Table'),[sales]))

The final output is shown below:

vyalanwumsft_1-1642742502515.pngvyalanwumsft_2-1642742511063.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create a slicer table ,then create a measure as follows:

1. enter a slicer table.

vyalanwumsft_0-1642735662477.png

2.create a measure.

 

Every-sales = 
var _year=CALCULATE(SUM([sales]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date]))))
var _month=CALCULATE(SUM([sales]),FILTER(ALL('Table'),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0)))
var _week=CALCULATE(SUM([sales]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date]))&&WEEKNUM([Date],2)=WEEKNUM(MAX([Date]),2)))

return
SWITCH(MAX('slicer'[slicer]),
"daily",SUM('Table'[sales]),
"Weekly",IF(WEEKDAY(MAX([Date]),2)=1,_week),
"month",IF(MAX([Date])=CALCULATE(MIN([Date]),FILTER(ALL('Table'),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0))),_month),
"year",IF(MAX([Date])=CALCULATE(MIN([Date]),FILTER(ALL('Table'),YEAR([Date])=YEAR(MAX([Date])))),_year),
"total",SUMX(ALL('Table'),[sales]))

 

The final output is shown below:

vyalanwumsft_1-1642735737163.pngvyalanwumsft_2-1642741448748.png

 


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable
amitchandak
Super User
Super User

@Anonymous , The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.


Anonymous
Not applicable

Hi have slicer with daily, Weekly, month and year and total. When the user selects daily i want the visuals, via a switch formula to all show dailys sales and when Weekly is selected then show weekly sales in all the visuals and so ...

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.

Top Solution Authors