Forum Discussion

jcastr02's avatar
jcastr02
Post Prodigy
2 years ago
Solved

Transform / Unpivot Columns

Hello I have below 4 columns with data but need to unpivot somehow to get desired results.  I 've tried all the possible unpivot actions but I can't get it work.  Any thoughts?

 

Current:

StoreTimeframeAverage Flu VolumeAvg Rx Volume
123Winter 20230.896696428192
45Winter 20231.805026641183
80Winter 20231.368312214168
20Winter 20230.483249572166
50Winter 20231.010349568130
60Summer 20240.756196089117.75
70Summer 20241.674370276312.75
80Summer 20241.257343793182

 

Desired:

StoreWinter 2023 - Average Flu VolumeWinter 2023 - Avg Rx VolumeSummer 2024 - Average Flu VolumeSummer 2024 - Avg Rx Volume
1230.896696428192  
451.805026641183  
801.368312214168  
200.483249572166  
501.010349568130  
60  0.756196089117.75
70  1.674370276312.75
80  1.257343793182
  • Hi jcastr02 
    If it is for visualization, you just need to use a Hierarchical matrix :

    Note that I added conditional column from PQ, for sorting in the needed order these columns

    Pbix is attached

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

  • Hi jcastr02 It is not an efficient way to work, but yes it is possible

     

    It is a lot of steps :

    You need to duplicate the tables twice, to pivot one table for average Rx

    Second for Avg Rx and to merge these pivoted tables.

    The updated pbix is attached, you can follow my steps.

    **I didn't format column names, you can modify them according to your needs.

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

4 Replies

  • Hi jcastr02 
    If it is for visualization, you just need to use a Hierarchical matrix :

    Note that I added conditional column from PQ, for sorting in the needed order these columns

    Pbix is attached

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

    • jcastr02's avatar
      jcastr02
      Post Prodigy

      Thanks Ritaf1983 I am needing to add it to a table visual that has other items tied to it - would there be a way to transform it on back end - so I can just pull the below in as columns to the visual?

      Winter 2023 - Average Flu VolumeWinter 2023 - Avg Rx VolumeSummer 2024 - Average Flu VolumeSummer 2024 - Avg Rx Volume
      • Ritaf1983's avatar
        Ritaf1983
        Super User

        Hi jcastr02 It is not an efficient way to work, but yes it is possible

         

        It is a lot of steps :

        You need to duplicate the tables twice, to pivot one table for average Rx

        Second for Avg Rx and to merge these pivoted tables.

        The updated pbix is attached, you can follow my steps.

        **I didn't format column names, you can modify them according to your needs.

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