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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Belle2015
Helper I
Helper I

Help with error when creating a measure for a date filter

Hi, 

I have had some help in creating a measure to create a filter to show the previous day's data or the weekend's data on a Monday but I am getting the below error 'The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value' and im not sure what I need to do to resolve this, sorry I am not so good with the more complex ones!

 

Belle2015_0-1738665996794.png

This is the table I want to filter - 

Count DateProductCounted byMore/LessDifference RecordedTotalStockPlusDiff% of Total Stock
29/01/2025623932Clerk 1More-154307-151558101.81%
29/01/2025623932Clerk 1Less154409151558101.88%
28/01/2025392-1269Clerk 4Less31543119101.12%
26/01/2025392-2036Clerk 3Less1508749220.13%
26/01/2025392-2069Clerk 3More-900018000-50.00%
22/01/2025206360Clerk 2Less343394318179.52%
21/01/2025392-1269Clerk 4More-77-13592.31%
20/01/2025203553Clerk 3More-3044113394-227.27%
19/01/20251213-2369Clerk 2More-1485-788188.45%
19/01/20252273069Clerk 2More-1200-0.50%
19/01/2025392-1036Clerk 4More-11143307-33.69%
16/01/20251213-5536Clerk 4Less555101549.50%
16/01/2025629610Clerk 4Less18351373513.36%
14/01/20251213-2369Clerk 4More-1935-1338144.62%
10/01/2025626129Clerk 1Less114183942897.97%
08/01/20251213-3636Clerk 5Less400104138.42%
08/01/20251213-5536Clerk 4More-3000-1949153.93%
08/01/20251213-5536Clerk 4More-385-334115.27%
07/01/2025392-1269Clerk 4More-53-38139.47%
04/01/2025629069Clerk 2Less34339985.96%

 

Thanks for any help 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Belle2015 

Based on your information, I create you table. At the same time, I added a piece of data from January 6th to test it.

Then create a new measure:

 

PreviousDayOrWeekendData = 
VAR TodayIsMonday = WEEKDAY(MAX('Table'[Count Date]), 2) = 1
VAR _PreviousDay = CALCULATE(SUM('Table'[TotalStockPlusDiff]), 'Table'[Count Date] = MAX('Table'[Count Date]) - 1)
VAR WeekendData = CALCULATE(SUM('Table'[TotalStockPlusDiff]), WEEKDAY('Table'[Count Date], 2) IN {6, 7} && 'Table'[Count Date] <= MAX('Table'[Count Date]))
RETURN
IF(TodayIsMonday, WeekendData, _PreviousDay)

 

 

Put this measure in table visual and create a slicer. Here is my preview:

vyohuamsft_0-1738826962621.png

 

When you select a slicer, the metrics also change. At the same time, it calculates the sum of the weekends up to the date selected by the current slicer.

vyohuamsft_1-1738827110534.png

 

vyohuamsft_2-1738827126042.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

7 REPLIES 7
Anonymous
Not applicable

Hi, @Belle2015 

Based on your information, I create you table. At the same time, I added a piece of data from January 6th to test it.

Then create a new measure:

 

PreviousDayOrWeekendData = 
VAR TodayIsMonday = WEEKDAY(MAX('Table'[Count Date]), 2) = 1
VAR _PreviousDay = CALCULATE(SUM('Table'[TotalStockPlusDiff]), 'Table'[Count Date] = MAX('Table'[Count Date]) - 1)
VAR WeekendData = CALCULATE(SUM('Table'[TotalStockPlusDiff]), WEEKDAY('Table'[Count Date], 2) IN {6, 7} && 'Table'[Count Date] <= MAX('Table'[Count Date]))
RETURN
IF(TodayIsMonday, WeekendData, _PreviousDay)

 

 

Put this measure in table visual and create a slicer. Here is my preview:

vyohuamsft_0-1738826962621.png

 

When you select a slicer, the metrics also change. At the same time, it calculates the sum of the weekends up to the date selected by the current slicer.

vyohuamsft_1-1738827110534.png

 

vyohuamsft_2-1738827126042.png

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

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

Thanks for your help with this, I think m not really explaining what I wanted it to do very well, I was hoping that it would work a bit like the relative date filter but without having to go in and select the days I wanted

Bibiano_Geraldo
Super User
Super User

Hi @Belle2015 ,

I just restructured your DAX to return the the desired scalar value, please try the bellow code and let me know if its all ok:

FilteredByDate = 
VAR TodayDate = TODAY()
VAR DayBefore = TodayDate - 1
VAR IsMonday = WEEKDAY(TodayDate, 2) = 1
RETURN
    CALCULATE(
        SUM('Table 2'[Difference Recorded]),
        FILTER(
            'Table 2',
            IF(
                IsMonday,
                'Table 2'[Count Date] = TodayDate - 3 || 
                'Table 2'[Count Date] = TodayDate - 2 || 
                'Table 2'[Count Date] = TodayDate - 1,
                'Table 2'[Count Date] = DayBefore
            )
        )
    )

Thanks so much for your help @Bibiano_Geraldo

Maybe I am not using this correctly but I though that I would just apply this measure to the filters to work but it is not filtering the table! Sorry I am very basic with this and trying to learn!

Belle2015_0-1738672768509.png

 

 

Preview
 
 
 

Hi whats is your expected resultt based on data you provided? i'll make some logic here to filter your data, just give me more context.

 

Thank you

Thanks for helping 🙂

I am trying to look at the counts done the previous day so as we can see what % of stock was used or added in, on a Monday I want to be able to see what was counted for on the Friday, Sat and Sunday. 

The table may have multiple counts done on the same product and it can be counted more than once on the same day. 

Hope that explains it ok.

danextian
Super User
Super User

Hi @Belle2015 

 

You can't return different table expressions based on conditions. Place each table expression in its own variable and then create a condition in the RETURN clause instead:

IF(
IsMonday,
CALCULATE(SUM('Table 2'[Difference Recorded]), filter01),
CALCULATE(SUM('Table 2'[Difference Recorded]), filter02)
)





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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