Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Barchart order based on parameter

Here’s a polished version of your query:


I have a graph structured as follows:

  • Y-axis: Categories (e.g., A, B, C, etc.)
  • Values:
    • Year-over-Year (YoY) Total (displayed in grey)
    • Year-over-Year (YoY) for a specific type (displayed in brown)

I want to introduce a parameter that allows the user to reorder the graph dynamically. The ordering options should include:

  1. Sorting by the YoY descending value for the Brown category .
  2. Sorting by the YoY desc for Total (grey).

How can I implement this functionality?

 

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi, Anonymous 

    Regarding the issue you raised, my solution is as follows:

    1.Firstly, I have created the following test data:

    To output the data in percentage form, please be mindful of the data type. Refer to the following:

    2.Secondly, I have created the following calculation table to serve as a slicer, allowing you to choose the sorting method:

    SortOrder = DATATABLE(
        "SortOrder", STRING,
        {
            {"Sort by YoY Brown"},
            {"Sort by YoY Total"}
        }
    )

    Please note that it is not necessary to establish a relationship between the calculation table and the original table.

    3.Below are the measure I've created for your needs:

    SortValue = 
    SWITCH(
        SELECTEDVALUE('SortOrder'[SortOrder]),
        "Sort by YoY Brown", MAX('Table'[YoY_Brown]),
        "Sort by YoY Total", MAX('Table'[YoY_Total]),
        MAX('Table'[YoY_Total])
    )
    

    4.Next, modify the visualisation settings:

    Parameter filling:

    Colour modification:

    Sorting:

    5.Here's my final result, which I hope meets your requirements.

    Please find the attached pbix relevant to the case.

     
    Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
     

    Best Regards,

    Leroy Lu

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

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Anonymous 

    Regarding the issue you raised, my solution is as follows:

    1.Firstly, I have created the following test data:

    To output the data in percentage form, please be mindful of the data type. Refer to the following:

    2.Secondly, I have created the following calculation table to serve as a slicer, allowing you to choose the sorting method:

    SortOrder = DATATABLE(
        "SortOrder", STRING,
        {
            {"Sort by YoY Brown"},
            {"Sort by YoY Total"}
        }
    )

    Please note that it is not necessary to establish a relationship between the calculation table and the original table.

    3.Below are the measure I've created for your needs:

    SortValue = 
    SWITCH(
        SELECTEDVALUE('SortOrder'[SortOrder]),
        "Sort by YoY Brown", MAX('Table'[YoY_Brown]),
        "Sort by YoY Total", MAX('Table'[YoY_Total]),
        MAX('Table'[YoY_Total])
    )
    

    4.Next, modify the visualisation settings:

    Parameter filling:

    Colour modification:

    Sorting:

    5.Here's my final result, which I hope meets your requirements.

    Please find the attached pbix relevant to the case.

     
    Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
     

    Best Regards,

    Leroy Lu

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