Forum Discussion

cathoms's avatar
cathoms
Responsive Resident
5 years ago
Solved

Transform data: To Pivot or Unpivot, that is the question.

Hello! I am still fairly new to Power Query and am struggling with how to transform some data from excel files. I am trying to get from this:

ServiceReceive DateQuestionsValuen%
Hospice Services7/1/2020 - 7/31/2020*Recommend the hospice careDefinitely no00
Hospice Services7/1/2020 - 7/31/2020*Recommend the hospice careProbably no14
Hospice Services7/1/2020 - 7/31/2020*Recommend the hospice careProbably yes28
Hospice Services7/1/2020 - 7/31/2020*Recommend the hospice careDefinitely yes2288
Hospice Services8/1/2020 - 8/31/2020*Recommend the hospice careDefinitely no00
Hospice Services8/1/2020 - 8/31/2020*Recommend the hospice careProbably no15
Hospice Services8/1/2020 - 8/31/2020*Recommend the hospice careProbably yes15
Hospice Services8/1/2020 - 8/31/2020*Recommend the hospice careDefinitely yes1890
Hospice Services9/1/2020 - 9/30/2020*Recommend the hospice careDefinitely no14.35
Hospice Services9/1/2020 - 9/30/2020*Recommend the hospice careProbably no14.35
Hospice Services9/1/2020 - 9/30/2020*Recommend the hospice careProbably yes00
Hospice Services9/1/2020 - 9/30/2020*Recommend the hospice careDefinitely yes2191.3

Etc.

 

To this:

ServiceReceive DateQuestionDef_No_NProb_No_NProb_Yes_NDef_Yes_NTotal_N
Hospice Services7/1/2020 - 7/31/2020*Recommend the hospice care0122225
Hospice Services8/1/2020 - 8/31/2020*Recommend the hospice care0111820
Hospice Services9/1/2020 - 9/30/2020*Recommend the hospice care1102123

 

There are also other questions in separate excel files that I need to transform in a similar fashion and ultimately merge together.

 

Thanks!

  • It is typically better to have data of the same type (in your case, questions and answers) left unpivoted to simplify analysis and visualization.  If unpivoted, two tables would be appended vs merged.  

     

    I used your data and made no data transformation, and made a Matrix visual on the report page to get your desired results.  See pic to see which field went where.

     

     

    Pat

     

3 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    It is typically better to have data of the same type (in your case, questions and answers) left unpivoted to simplify analysis and visualization.  If unpivoted, two tables would be appended vs merged.  

     

    I used your data and made no data transformation, and made a Matrix visual on the report page to get your desired results.  See pic to see which field went where.

     

     

    Pat

     

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    You should leave your data unpivoted, and append the data from the other files.  You can pivot it back out in your visuals and write measures to get your desired results.  "Rows before co-s" (columns).

    Pat

     

    • cathoms's avatar
      cathoms
      Responsive Resident

      I don't mean to sound glib, rather naive I suppose, but... Why would I do that? What is the value of "rows before co-s"?

       

      Thanks!