Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Using slicer for sum of columns

Suppose I have the following data:

 

NameCountryJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember
AlexUSA140741213981310018683135
AndrewUSA57246732213729805492534
DiegoSpain8410052328611697477267385
GeorgeCanada30958944854197385115919
JohnAustralia4790165580879871479375
LauraSpain662476827192596468781684
MaryCanada144964449149962676253334
SantiagoSpain55973282718831278955775

 

I want to have a slicer with the months of the year, allowing single or multiple segmentation at once. With that I'd like to have a table (or any graphic) that shows the sum of the values for each country, depending on the months selected in the slicer.

 

For example:

If only January is selected as a filter we would obtain this count: USA - 71, Spain - 205, Canada - 44, Australia - 47. However, if we select from January, February and March in the slicer, we would obtain: USA - 236, Spain - 586, Canada - 341, Australia - 153.

 

I need help on how to handle this problem, since I don't know how to turn "Months" into a slicer.

 

Thanks in advance.

  • Hey Anonymous ,

     

    you should unpivot the month columns. You can do that like this:

     

     

    Then you can rename the "Attribute" column to "Date", replace the values with real dates and then you can slice by date in the report.

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis
     
  • Anonymous understood, but as a best practice and a scalable solution, it is always good to have unpivoted data. There is always create a better model or write a complex DAX to achieve the business goal. You decide what to pick. So better to revisit your solution by revisiting that this needs to be unpivoted. All the best. 

     

    Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • Anonymous's avatar
    Anonymous
    5 years ago

    Anonymous 

    Dax calculation is based on rows not column, the best solution for is to transform the table making the month into rows then you can create a slicer to filter to interact. If you are worrying about later report creation. You can just duplicate the table then use the new table for this sum calculation.

     

     

    Paul Zheng _ Community Support Team
    If this post helps, please Accept it as the solution to help the other members find it more quickly.

6 Replies

  • Anonymous understood, but as a best practice and a scalable solution, it is always good to have unpivoted data. There is always create a better model or write a complex DAX to achieve the business goal. You decide what to pick. So better to revisit your solution by revisiting that this needs to be unpivoted. All the best. 

     

    Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • Anonymous you need to unpivot your data in PQ

     

    - transform data
    - select name and country columns in the table
    - right-click, unpivot other columns it will add two columns, attribute, and value, rename these as per your requirement
    - close and apply

    Now you can slice the data by months.

     

    Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • Anonymous's avatar
      Anonymous
      Not applicable

      parry2k thanks for the response.

       

      Question: this is a simplified example of the real data that I'm handling, and the dashboards has many others graphics and variables. If I unpivot my data wouldn't that make more difficult the ellaboration of my dashboard? Is there any other alternative to the stated problem?

  • selimovd's avatar
    selimovd
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hey Anonymous ,

     

    you should unpivot the month columns. You can do that like this:

     

     

    Then you can rename the "Attribute" column to "Date", replace the values with real dates and then you can slice by date in the report.

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis
     
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hey selimovd  thanks for the help.

       

      I wonder if there is any other alternative to solve this. Since this is a very simplified example of the real data that I'm handling, and the dashboard has many others graphics and variables, I don't know if by "unpivoting" my data, managing the information of the other columns would be more difficult.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous 

    Dax calculation is based on rows not column, the best solution for is to transform the table making the month into rows then you can create a slicer to filter to interact. If you are worrying about later report creation. You can just duplicate the table then use the new table for this sum calculation.

     

     

    Paul Zheng _ Community Support Team
    If this post helps, please Accept it as the solution to help the other members find it more quickly.