Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

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: 

OppIDStage1Stage2Stage3Stage4Stage5
ABC123ProspectingQualifyingEstimatingProposingClosing

 

The data table is set up to record changes in the stage name so the data comes across as follows:

OppIDDateOldValueNewValue
ABC1231/1/2020ProspectingQualifying
ABC1231/2/2020QualifyingEstimating
ABC1231/3/2020EstimatingProposing
ABC1231/4/2020ProposingClosing

 

 

Any help with this would be super helpful... i've been trying to figure this out for some time.  Thanks in advance!

12 Replies

  • 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!

     

  • v-eachen-msft's avatar
    v-eachen-msft
    Icon for Community Support rankCommunity 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.

     

    • Anonymous's avatar
      Anonymous
      Not 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's avatar
        v-eachen-msft
        Icon for Community Support rankCommunity Support

        Hi Anonymous ,

         

        Do you have multiple OppIDs?

         

  • 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?

  • 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.

    1-1.PNG

  • 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.

    1-1.PNG