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
DebbieE
Community Champion
Community Champion

DAX for percentage of day from a week with year Slicer

I think I have managed to figure out creating a matrix of % Order quanity over the days of the week

 

I added Year Week to the SQL Dim Date Table. For example

202101

202152

 

(Padding out the weeks 1 to 9 and changing back to number)

 

And then created a DAX Query based on a question I asked yesterday

 

Order Quantity by Week % =
Var varOrderQtyWeek = CALCULATE(SUM(FactResellerSales[Order Quantity]), FILTER(ALL(DimDate), DimDate[Year Week]))
RETURN DIVIDE(SUM(FactResellerSales[Order Quantity]), varOrderQtyWeek))
And without a slicer it works fine
Matrix.JPG
However as soon as I introduce the year slicer (I Only want Sundays in 2021 for example it fails to tell the story i need
matrixWithSlicer.JPG
So its right, in the year selected for accessories we had 31% of sales, but I want that specified year to be the range its looking at so it comes out as 100%.
 
I have tried ALLEXCEPT, ALLSELECTED, and nothing has worked. How do i update the DAX above so it resets the range to just calendar year and gives me the percentage of quanity sold on the Monday in the week based on just the year?
2 REPLIES 2
VahidDM
Super User
Super User

Hi @DebbieE 


Try this:

Order Quantity by Week % =
VAR varOrderQtyWeek =
    ADDCOLUMNS (
        CALCULATETABLE ( VALUES ( DimDate[Year Week] ), REMOVEFILTERS ( DimDate[Day Nme] ) ),
        "SumQ", SUM ( FactResellerSales[Order Quantity] )
    )
VAR _WQ =
    SUMX ( varOrderQtyWeek, [SumQ] )
VAR _DWQ =
    SUM ( FactResellerSales[Order Quantity] )
RETURN
    _DWQ / _WQ

 

DimDate[Day Nme] = column you used in the matrix's columns.

 

If it does not work, can you share a sample of your data?

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

DebbieE
Community Champion
Community Champion

The above didnt work

AgainNope.JPG

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