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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
BachDinh
Helper I
Helper I

Returning a value based on day of the week

Hi, 

 

I need to return a value based off the day of the week. I created two SWITCH variables as below: 

 

var cluster_target_weekday = 
CALCULATE(
    SWITCH(
        TRUE()
        ,cluster_type = "1", 35
        ,cluster_type = "2", 45
        ,cluster_type = "3", 55
        ,cluster_type = "4", 55
        ,cluster_type = "5", 60
        ,cluster_type = "6", 60
    )
)

var cluster_target_weekend = 
CALCULATE(
    SWITCH(
        TRUE()
        ,cluster_type = "1", 40
        ,cluster_type = "2", 50
        ,cluster_type = "3", 60
        ,cluster_type = "4", 60
        ,cluster_type = "5", 65
        ,cluster_type = "6", 70
    )
)

 

And now I want to populate the correct target based on the date and kiosk classification (another variable), with the sample output like this:

 

Cluster type12/02/202313/02/202314/02/202315/02/2023 
140353535 
250454545 
360555555 
460555555 

 

As IF(Date[Date]) within a CALCULATE function doesn't work since there's multiple dates, I am not sure what to do about this.

5 REPLIES 5
PawelWrona
Resolver I
Resolver I

Is the Date table your Calendar table? If yes, you can have a calculated column there indicating whether this is a weekday or a weekend.

MURTAZA
Resolver I
Resolver I

How about you create another variable to check weekend/weekday:

 

VAR _Weekend = IF ( WEEKDAY ( 'Date'[Date]) IN { 1, 7 }, "Weekend" , "Weekday" )

 


Then RETURN a combined function with _Weekend check, something like:

 

RETURN
cluster_target = 
    SWITCH(
        TRUE(),
        _Weekend = "Weekday" && cluster_type = "1", 35,
        _Weekend = "Weekend" && cluster_type = "1", 40,
and so on.

 



It doesn't allow me to use the 'Date'[Date] from the calendar table in the variable unfortunately. 

After looking at it, I think it won't allow aggregation of the calendar table for the WEEKDAY() function?

oh right, Create a calculated column in your date table then and then. 

 

Weekend/Weekday = IF ( WEEKDAY ( 'Date'[Date]) IN { 1, 7 }, "Weekend" , "Weekday" )

 

then this measure should work

 

cluster_target = 
    SWITCH(
        TRUE(),
        Weekend/Weekday = "Weekday" && cluster_type = "1", 35,
        Weekend/Weekday = "Weekend" && cluster_type = "1", 40,
and so on.

I hope this works. Else upload a .pbix

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.