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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Fragmaticx
Frequent Visitor

CalculationGroups - switch between dates

Hi 

I have a model where I use calculaton groups to switch between dates.

Lets say its a Order Date and Delivery Date - and I want to make a calculation based of the 2 dates.

 

I think i need something like, if selectedmeasure is OperationalDate then 

   BaseData[ShipmentPeriod] <> BaseData[OperationalPeriod]
elseif 

Selectedmeasure is ShipmentPeriod then
 BaseData[OperationalPeriod] <>    BaseData[ShipmentPeriod]


Lastmile Cost - Different Period = 
                CALCULATE(
                    SUMX(BaseData, BaseData[AmountDKK]),
                    FILTER(
                        BaseData,
                        BaseData[Type] = 2 &&
                        BaseData[TransportType] = 1 && 
                        BaseData[ShipmentPeriod] <> BaseData[OperationalPeriod]
                    )
                )

 

but I dont know how to do it?

1 ACCEPTED SOLUTION

Hi @Fragmaticx please try this

 

Lastmile Cost - Different Period =
VAR CurrentCalcItem = SELECTEDVALUE ( 'DateToUse'[Calculation group column] )
RETURN
CALCULATE (
    SUM ( BaseData[AmountDKK] ),
    BaseData[Type] = 2,
    BaseData[TransportType] = 1,
    SWITCH (
        CurrentCalcItem,
        "OperationalPeriod", BaseData[ShipmentPeriod] <> BaseData[OperationalPeriod],
        "ShipmentPeriod", BaseData[OperationalPeriod] <> BaseData[ShipmentPeriod]
    )
)
Power BI & Microsoft Fabric
Blog: https://medium.com/@cseprs_54978

View solution in original post

7 REPLIES 7
v-hashadapu
Community Support
Community Support

Hi @Fragmaticx , Thank you for reaching out to the Microsoft Community Forum.

 

We find the answer shared by @techies  is appropriate. Can you please confirm if the solution worked for you. It will help others with similar issues find the answer easily.
Thank you @techies  for your valuable response.

v-hashadapu
Community Support
Community Support

Hi @Fragmaticx , Hope you're doing okay! May we know if it worked for you, or are you still experiencing difficulties? Let us know — your feedback can really help others in the same situation.

v-hashadapu
Community Support
Community Support

Hi @Fragmaticx , hope you are doing great. May we know if your issue is solved or if you are still experiencing difficulties. Please share the details as it will help the community, especially others with similar issues.

Fragmaticx
Frequent Visitor

Hi everybody,

This is a small sample set.

I have a calculation group: DateToUse
Item 1: 

SELECTEDMEASURE ()


Item 2: 

CALCULATE ( SELECTEDMEASURE (), USERELATIONSHIP ( BaseData[ShipmentPeriod], 'DateTable'[Date] ) )





 

OperationalPeriodShipmentPeriodAmountDKKTypeCustomerTransportType
01-08-202501-08-20251002Dennis1
01-07-202501-08-20251502Dennis1

 

 

 

Lastmile Cost - Different Period =
CALCULATE(
    SUMX(
        BaseData,
        BaseData[AmountDKK]
    ),
    FILTER(
        BaseData,
        BaseData[Type] = 2 &&
        BaseData[TransportType] = 1 &&
        BaseData[ShipmentPeriod] <> BaseData[OperationalPeriod]
    )
)



I expect it to show if ShipmentPeriod is selected then it should be 0 since both lines are within that period, and if OperationalPeriod is selected it should show 150, since they are 01-07-2025.

I appriciate your help,


 

Hi @Fragmaticx please try this

 

Lastmile Cost - Different Period =
VAR CurrentCalcItem = SELECTEDVALUE ( 'DateToUse'[Calculation group column] )
RETURN
CALCULATE (
    SUM ( BaseData[AmountDKK] ),
    BaseData[Type] = 2,
    BaseData[TransportType] = 1,
    SWITCH (
        CurrentCalcItem,
        "OperationalPeriod", BaseData[ShipmentPeriod] <> BaseData[OperationalPeriod],
        "ShipmentPeriod", BaseData[OperationalPeriod] <> BaseData[ShipmentPeriod]
    )
)
Power BI & Microsoft Fabric
Blog: https://medium.com/@cseprs_54978
techies
Super User
Super User

Hi @Fragmaticx As i understand, you can try using ISSELECTEDMEASURE where you want change depending on measures shipment based, operational based

 

Please share sample datasets to test 

 

 

 

Power BI & Microsoft Fabric
Blog: https://medium.com/@cseprs_54978
FBergamaschi
Solution Sage
Solution Sage

I am unsure as to what you are trying to do

 

Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

 

Need help uploading data? click here

 

Want faster answers? click here

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.