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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
LukeWeeCMG
New Member

Managing Row Context with Date Slicer in DAX

Greetings all,

 

I am having troubles in "thinking in DAX" to create the desired table while having a Date Slicer

 

I have Tthree tables:
1.  Date Control Table - A table that contains the calendar dates (Date Control Table)[Date]
2.  Store Table - A table that contains the information for stores that includes (Store)[StoreRegion] and (Store)[StoreID]
3.  Target Distribution Table - A table that contains the Sales Target Data of Stores that includes (Target Distribution)[StoreID], (Target Distribution) [Date], (Target Distribution) [Sales Target]

In addtion, i created a measure to get the date from the slicer called [Report Slicer Date] which i use as a date variable for my measures.

I am trying to develop a DAX to get the Total Sales Target of the month for each Store Region  accroding to Date Selected by the Date Slicer. However, I am only able to get the Total Values of all the Store Region instead of the Total Sales Target for each Store Region as shown below.

LukeWeeCMG_0-1696233621327.png


This is the DAX formula i devised for Target_Month:

 

 

 

Target_Month = 
VAR CurrentDate = [Report Slicer Date]
VAR StartMonth = DATE(YEAR(CurrentDate), MONTH(CurrentDate), 1)
VAR EndMonth = EOMONTH(CurrentDate, 0)
RETURN 
    CALCULATE(
        SUM('Target Distribution'[Value]),REMOVEFILTERS(), ALLEXCEPT('Store','Store'[StoreRegion], Store[StoreID]),
       DATESBETWEEN(
            'Target Distribution'[Date], 
            StartMonth, 
            EndMonth
        ) 
    )

 

 


I need help to modify the DAX so it can return the Total Sales Target for each store from the selected date. Please you need any more clarification.

 

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @LukeWeeCMG ,

 

Based on your description, I suggest modifying your DAX formula as follows:

Target_Month = 
VAR CurrentDate = [Report Slicer Date]
VAR StartMonth = DATE(YEAR(CurrentDate), MONTH(CurrentDate), 1)
VAR EndMonth = EOMONTH(CurrentDate, 0)
RETURN 
    CALCULATE(
        SUM('Target Distribution'[Sales Target]),
        ALLEXCEPT('Store','Store'[StoreRegion]),
        DATESBETWEEN(
            'Target Distribution'[Date], 
            StartMonth, 
            EndMonth
        ) 
    )

The ALLEXCEPT function removes all filters from the Store table except for the StoreRegion column. This ensures that the calculation is performed at the StoreRegion level. The SUM function calculates the total sales target for each store region based on the selected date.

 

Best Regards,

Stephen Tao

 

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

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @LukeWeeCMG ,

 

Based on your description, I suggest modifying your DAX formula as follows:

Target_Month = 
VAR CurrentDate = [Report Slicer Date]
VAR StartMonth = DATE(YEAR(CurrentDate), MONTH(CurrentDate), 1)
VAR EndMonth = EOMONTH(CurrentDate, 0)
RETURN 
    CALCULATE(
        SUM('Target Distribution'[Sales Target]),
        ALLEXCEPT('Store','Store'[StoreRegion]),
        DATESBETWEEN(
            'Target Distribution'[Date], 
            StartMonth, 
            EndMonth
        ) 
    )

The ALLEXCEPT function removes all filters from the Store table except for the StoreRegion column. This ensures that the calculation is performed at the StoreRegion level. The SUM function calculates the total sales target for each store region based on the selected date.

 

Best Regards,

Stephen Tao

 

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

sergej_og
Post Prodigy
Post Prodigy

Hey @LukeWeeCMG ,
one question before adjusting DAX.

Do you have a proper connected data model?
Are relathionships between your 3 tables valid?

Regards

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.