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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Calculate Gross Sales Variance Based on Selected filtered Dates

Hello,

 

I'm new with DAX and had a question about how to calculate the variance of gross sales between two months. The two months selections are to going to be filters/slicers.

 

I have three simplete tables.

 

geopoo88_0-1605211462312.png

Data table looks like this.

Forecast Date Measure Amount
6/1/2020 Gross Sales 1,000
7/1/2020 Gross Sales 2,000
8/1/2020 Gross Sales 3,000
9/1/2020 Gross Sales 2,000
10/1/2020 Gross Sales 1,500
11/1/2020 Gross Sales 500
12/1/2020 Gross Sales 3,250

 

I want to write a formulate that calculates the difference in gross sales (CM Gross Sales - PM Gross Sales), however the filter for the forecast dates needs to come from the filtered selection.

 

Something like this.

Gross Sales Var = calculate(sum([Amount]),Filter(XXCM SelectionXX) - calculate(sum([Amount]),Filter(XXPM SelectionXX)

The XXSelection needs to be the months selected in the filters.

 

Any help?


Thanks

 

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Here are the steps you can follow:

1. Create measure.

 

Measure 2 =
var _max=MAX('Table'[Forecast Date])
var _min=MIN('Table'[Forecast Date])
return CALCULATE(SUM('Table'[Amount]),FILTER('Table','Table'[Forecast Date]=_max))-CALCULATE(SUM('Table'[Amount]),FILTER('Table','Table'[Forecast Date]=_min))

 

2. Result.

v-yangliu-msft_0-1605489869927.jpeg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

DataInsights
Super User
Super User

@Anonymous,

 

Try this measure. Each slicer is based on its corresponding table (e.g., CM Forecast Date slicer is based on 

CMFCST[CM Forecast Date]). No relationships exist between the three tables.

 

Gross Sales Var = 
VAR vCMDate =
    SELECTEDVALUE ( CMFCST[CM Forecast Date] )
VAR vPMDate =
    SELECTEDVALUE ( PMFCST[PM Forecast Date] )
VAR vCMAmount =
    CALCULATE ( SUM ( Data[Amount] ), Data[Forecast Date] = vCMDate )
VAR vPMAmount =
    CALCULATE ( SUM ( Data[Amount] ), Data[Forecast Date] = vPMDate )
VAR vResult = vCMAmount - vPMAmount
RETURN
    vResult

 

 

DataInsights_0-1605378877253.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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