Forum Discussion
Shifting values from multiple rows to one row for Unique ID...
I'm using Power BI connecting to Salesforce to access the Opportunity Field History object (table). I'd like to end up with each stage an opportunity hits, in order, on a single row so I can then build a flow diagram to illustrate pull through and fall out.
Solution Example:
| OppID | Stage1 | Stage2 | Stage3 | Stage4 | Stage5 |
| ABC123 | Prospecting | Qualifying | Estimating | Proposing | Closing |
The data table is set up to record changes in the stage name so the data comes across as follows:
| OppID | Date | OldValue | NewValue |
| ABC123 | 1/1/2020 | Prospecting | Qualifying |
| ABC123 | 1/2/2020 | Qualifying | Estimating |
| ABC123 | 1/3/2020 | Estimating | Proposing |
| ABC123 | 1/4/2020 | Proposing | Closing |
Any help with this would be super helpful... i've been trying to figure this out for some time. Thanks in advance!
12 Replies
- parry2k
Super User
Anonymous you should add another column for stage and then it should be easy
Stage = SWITCH ( Table[Old Value], "Prospecting", "Stage 1", "Qualifying", "State 2", "Estimating", "Stage 3", "Proposing", "Stage 4", "Stage 5" )and use this new column on columns in the matrix visual
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
- AnonymousNot applicable
Not sure that would work due to our lack of restriction. Unfortunately, our Salesforce team hasn't locked down starting positions, at least not until recently. So a salesperson could enter an opportunity in the estimating stage and that would technically be Stage 1. And then from there it moves to Proposing (or wherever) which would be Stage 2 for that opportunity.
Weird, I know.
- parry2k
Super User
Anonymous I guess then you need to rank the status and then based on the rank, set the stage
read more about ranking here.
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
- v-eachen-msft
Community Support
Hi Anonymous ,
You could refer to the following DAX:
Column = RANKX ( FILTER ( 'Table', 'Table'[OppID] = EARLIER ( 'Table'[OppID] ) ), 'Table'[Date], , ASC, DENSE )Table 2 = SUMMARIZE ( 'Table', "ID", DISTINCT ( 'Table'[OppID] ), "Stage 1", CALCULATE ( SELECTEDVALUE ( 'Table'[OldValue] ), 'Table'[Column] = 1 ), "Stage 2", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 1 ), "Stage 3", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 2 ), "Stage 4", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 3 ), "Stage 5", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 4 ) )Here is my test result.
- AnonymousNot applicable
v-eachen-msft I was super excited for this, but it threw an error for me when attmpting to execute the table:
"A table of multiple values was supplied where a single value was expected."
Any thoughts?
- v-eachen-msft
Community Support
Hi Anonymous ,
Do you have multiple OppIDs?
- Ashish_Mathur
Super User
Hi,
I think we can carry out some transformations in the Query Editor to solve this. Are Power Query trnsformations allowed when you directly soruce data from SalesForce?
- Syndicate_Admin
Administrator
Hi @jdonovan ,
You can refer to the following DAX:
Column = RANKX ( FILTER ( 'Table', 'Table'[OppID] = EARLIER ( 'Table'[OppID] ) ), 'Table'[Date], , ASC, DENSE )Table 2 = SUMMARIZE ( 'Table', "ID", DISTINCT ( 'Table'[OppID] ), "Stage 1", CALCULATE ( SELECTEDVALUE ( 'Table'[OldValue] ), 'Table'[Column] = 1 ), "Stage 2", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 1 ), "Stage 3", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 2 ), "Stage 4", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 3 ), "Stage 5", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 4 ) )Here is the result of my test.
- Syndicate_Admin
Administrator
Hi @jdonovan ,
You can refer to the following DAX:
Column = RANKX ( FILTER ( 'Table', 'Table'[OppID] = EARLIER ( 'Table'[OppID] ) ), 'Table'[Date], , ASC, DENSE )Table 2 = SUMMARIZE ( 'Table', "ID", DISTINCT ( 'Table'[OppID] ), "Stage 1", CALCULATE ( SELECTEDVALUE ( 'Table'[OldValue] ), 'Table'[Column] = 1 ), "Stage 2", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 1 ), "Stage 3", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 2 ), "Stage 4", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 3 ), "Stage 5", CALCULATE ( SELECTEDVALUE ( 'Table'[NewValue] ), 'Table'[Column] = 4 ) )Here is the result of my test.