Search code examples
powerbidaxmeasure

How do I create a series of measures in Power BI for each day of the week with multiple filters?


I would like to create a series of measures that shows my current week's sales by day. Example: 1 measure shows Sunday's sales, 1 measure shows Monday's sales, etc.

In order to identify the current week, I have added a field to my date table called 'Week Rank' in combination with the max function.

When I use the below formula, I get a very wrong answer. Trying to figure out what the figure is, but no luck so far. What is wrong with my formula?

Sunday Sales = calculate(sum('Transaction_Data'[TotalSales]),filter(all('Dates'), Dates[DayOfWeekName]="Sunday" || Dates[Week Rank]=MAX('Dates'[Week Rank])))


Solution

  • Below will work, and will be very easy to copy-paste 6 more times. You just have to change the measure name and the value of the this_day variable.

    I would like to point out that the REMOVEFILTERS statement is a replacement for the ALL statement in your version. In this scenario, they are interchangeable; however, REMOVEFILTERS offers more clarity and, IMO, should be used when ALL is being used for the purpose of eliminating filters.

    Sunday Sales = 
    
    var this_day = "Sunday"
    var this_week = MAX(Dates[Week Rank])
    
    RETURN
    CALCULATE(SUM('Transaction_Data'[TotalSales]),
        REMOVEFILTERS(Dates),
        Dates[DayOfWeekName]= this_day,
        Dates[Week Rank] = this_week
    )