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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
RT6
Frequent Visitor

DAX, Previous Shift, previous Week Dynamic Switch

Hi all,

 

i have a datasets with several records including timestamp. The requirement is to have a filter to be able to select 

1). Current Shift (6:00-14:00, 14:00-22:00, 22:00-6:00)

2). Today Overview

3). Current Week

4). Current Month

 

With possibility to see previous period for some visuals. What is the best approach? I have tried to use Field Parameters with calcualtions Current and Previous Periods. But the issue is to do proper Switch for the previous week and shift.

 

Structure of the input json: 

 

{"timestamp":"2024-03-06T10:40:36","resource_name":"dmg_ctx_beta_1250_tc_1","datamodel_version":"general_v_1_0_0","resource":"101","active_program_current_state_number":"0","active_program_last_transition_number":"2","active_program_name":"_N_CH12_ROBOTER_SPF","errorcode":"0","message":"","production_desired_parts":"410","production_part_counter":""}
{"timestamp":"2024-03-06T10:40:37","resource_name":"dmg_ctx_beta_1250_tc_1","datamodel_version":"general_v_1_0_0","resource":"101","active_program_current_state_number":"1","active_program_last_transition_number":"0","active_program_name":"_N_CM100GE000010_MPF","errorcode":"0","message":"","production_desired_parts":"410","production_part_counter":""}

2 REPLIES 2
amitchandak
Super User
Super User

@RT6 , I think you should explore offset function with an order by partition by

 

Continue to explore Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi Amitchandak, thanks for your response, for now the solution was to create measures for each period and use Dynamic Switch: 

Dynamic_TotalTime_Diff =
SWITCH(
    SELECTEDVALUE(SlicerTable[Period]),
    "Current Shift", [_CS_TotalTimeDiff],
    "Today", [_Today_TotalTimeDiff],
    "This Week", [_ThisWeek_TotalTimeDiff],
    "This Month", [_ThisMonth_TotalTimeDiff],
    BLANK()
)
 
And Slicer Table: 
SlicerTable =
DATATABLE(
    "Period", STRING,
    "Order", INTEGER,
    {
        {"Current Shift", 1},
        {"Today", 2},
        {"This Week", 3},
        {"This Month", 4}
    }
It seems to be working🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.