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

Get TotalSales base on Selected Month

I have a MonthSelection table which contain MonthDate and this doesn't have any relationships (Standalone table). 

Also, I have SalesTbl table which contains MonthDate, Product, Sales and Cost, and a DateTbl containing MonthDate, Year, MonthName. SalesTbl and DateTbl has relationship base on MonthDate. 

EalTim_0-1631722457055.png

 

I have a measures

TotalSales = Sum(SalesTbl[Sales])

I created a table visual that have Product and MonthSelection Slicers

EalTim_1-1631722457059.png

 

My question is how can I calculate TotalSales to show data greater than or equal to Month selected in the MonthSelection Slicer as shown below

EalTim_2-1631722457071.png

 

I tried using this measure 

TotalSales based on Monthselected = CALCULATE(Sum(SalesTbl[Sales]), FILTER(ALL(DateTbl), DateTbl[MonthDate] = SELECTEDVALUE(MonthSelection[MonthDate])

but didn't work.

How can i achieve this?

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@Anonymous 

Check the pbix for detail.

 

Vpazhenmsft_0-1632117912641.png

 

The monthdate column must be Date type.

1. Create a separated and disconnected table and use it as slicer: Slicer = DISTINCT( 'Table'[MonthDate] )

2. Create a measure to get the sales later than the selected month date:

Sales = CALCULATE(SUM([Total Sales]),FILTER('Table',[MonthDate]>=SELECTEDVALUE(Slicer[MonthDate])))

Vpazhenmsft_1-1632117933498.png

 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
V-pazhen-msft
Community Support
Community Support

@Anonymous 

Check the pbix for detail.

 

Vpazhenmsft_0-1632117912641.png

 

The monthdate column must be Date type.

1. Create a separated and disconnected table and use it as slicer: Slicer = DISTINCT( 'Table'[MonthDate] )

2. Create a measure to get the sales later than the selected month date:

Sales = CALCULATE(SUM([Total Sales]),FILTER('Table',[MonthDate]>=SELECTEDVALUE(Slicer[MonthDate])))

Vpazhenmsft_1-1632117933498.png

 

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

CNENFRNL
Community Champion
Community Champion

Screenshot 2021-09-15 232752.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

In fact, use a disconnected table as slicer is way much easier to author a measure; I keep the relationship on purpose to force myself to keep a clear mind over filter modifications during the calculation.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

@CNENFRNL 

Thanks for the reply and pbix which works fine.

but i tried to used that dax for my real scenario and the DAX i used is

measure =
VAR BaseMonthselected = SELECTEDVALUE(MonthSelectionTable[EndMonth])
RETURN
IF(
CALCULATE(  HASONEVALUE(CalendarBridgeTable[EndMonth]), REMOVEFILTERS(MonthSelectionTable[EndMonth])
),
IF(
CALCULATE(MAx(CalendarTable[EndMonth]), REMOVEFILTERS(MonthSelectionTable[EndMonth])) >= BaseMonthselected,
CALCULATE( [TotalBase],REMOVEFILTERS(MonthSelectionTable[EndMonth]))
),
SUMX(  FILTER(
ALLSELECTED(CalendarBridgeTable[EndMonth]),
CalendarTable[EndMonth] >= BaseMonthselected
),
CALCULATE( [TotalBase],REMOVEFILTERS(MonthSelectionTable[EndMonth]))
) )

This didn't work for me. How can I just the dax to work properly.

Note:

the CalendarTable[EndMonth] is on the visual,

MonthSelectionTable[EndMonth] is on the slicer and is not connected or have any relationship,

[Total Base] is the measure that is already calculated.
Thanks

mh2587
Super User
Super User

please replace FILTER(ALL(DateTbl) with FILTER(ALLSELECTED(DateTbl) hope this will give desired output


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Anonymous
Not applicable

@mh2587 I change it to FILTER(ALLSELECTED(DateTbl) but it didn't work

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.