Forum Discussion

joshua1990's avatar
joshua1990
Post Prodigy
1 year ago
Solved

SWITCH for 2 different date columns

I have a report that displays daily sales. In the sales table, I have two columns with date information.

I would like to have a switch in the report that distinguishes between both perspectives.

What is the most elegant way to achieve this? Field parameters with selected value and USERELATIONSHIP?

  • Click here to downlaod a solution from one drive.

    Look at the documentation on all pages, on the relationships and inside the dax measures

    Please click thumbs up and accept solution button. Thank you

     

    Click here 

     

     

  • Hi joshua1990,

     

    Thank you for providing information on your issue. I’ve reviewed your scenario and successfully replicated it using sample data on my end.

    I’m sharing the working .pbix file below so you can explore the setup and DAX logic more clearly. Please feel free to open it and review how the relationships and measures are configured:

     

    I hope this helps resolve your issue. If you have any questions or need further clarification, I’m happy to help.

    If you found this post useful, kindly give it a ‘Kudos’ and mark it as a solution so others facing similar challenges can find it more easily.

    Thanks for being part of the Microsoft Community!

7 Replies

  • Click here to downlaod a solution from one drive.

    Look at the documentation on all pages, on the relationships and inside the dax measures

    Please click thumbs up and accept solution button. Thank you

     

    Click here 

     

     

  • v-sgandrathi's avatar
    v-sgandrathi
    Community Support

    Hi joshua1990,

     

    Thank you for providing information on your issue. I’ve reviewed your scenario and successfully replicated it using sample data on my end.

    I’m sharing the working .pbix file below so you can explore the setup and DAX logic more clearly. Please feel free to open it and review how the relationships and measures are configured:

     

    I hope this helps resolve your issue. If you have any questions or need further clarification, I’m happy to help.

    If you found this post useful, kindly give it a ‘Kudos’ and mark it as a solution so others facing similar challenges can find it more easily.

    Thanks for being part of the Microsoft Community!

    • v-sgandrathi's avatar
      v-sgandrathi
      Community Support

      Hi joshua1990,

       

      Just checking in! We noticed you haven’t responded yet, and we want to make sure your question gets fully resolved.

      Let us know if you need any additional support. If the previous answer addressed your concern, feel free to mark it as Accepted and give it a Kudos to help others with similar queries.

       

      Thanks again for contributing to the Microsoft Fabric Community!

      • v-sgandrathi's avatar
        v-sgandrathi
        Community Support

        Hi joshua1990,

        Hope you're doing well!

        Just following up to see if the response we shared was helpful. If you have any further questions or need clarification, we’re here to assist.

        Thanks for being a part of the Microsoft Fabric Community!

  • Hi joshua1990  - You can only have one active relationship to a table at a time, so the second one must stay inactive.

    Create a new table (e.g., Like DatePerspective)>>A slicer-friendly column>> A parameter measure: Perspective

    Parameter

    Create a measure with userrelationship as below:

    SalesAmountSelectedDate =
    VAR SelectedDateColumn = SELECTEDVALUE('Date Perspective'[Date Perspective])
    RETURN
    SWITCH(
    TRUE(),
    SelectedDateColumn = "OrderDate",
    CALCULATE(SUM(Sales[SalesAmount])), -- Active relationship
    SelectedDateColumn = "DeliveryDate",
    CALCULATE(SUM(Sales[SalesAmount]), USERELATIONSHIP(Sales[DeliveryDate], Calendar[Date])),
    -- Default fallback
    CALCULATE(SUM(Sales[SalesAmount]))
    )

     

    Hope this works, try and let know.

  • Hi joshua1990 

     

    I went to a lot of effort to provide an explanation and example.
    Did you try my method?

    Please click thumbs up and the [accept as solution] buttons.

    It is polite and sensible to thank helpers this way.  😀