Forum Discussion

YeltsinC's avatar
YeltsinC
Regular Visitor
5 years ago
Solved

Prepare Target source data for Sankey diagram

Hello,

 

I am trying to create a Sankey Diagram with the overview of changes over time in each Department over each year (or potentially a smaller period) and am looking for a way to transform the dataset that I am dealing with. However, the options that I have found online do not quite deal with the problem that I have.

 

My source table looks like this:

 

IDDEPYEARValueSNKID
1X120191X1 2019
2X220191X2 2019
3X320191X3 2019
4X120191X1 2019
5X220191X2 2019
6X320191X3 2019
7X120191X1 2019
8X220191X2 2019
9X320191X3 2019
10X120191X1 2019
1X220201X2 2020
2X220201X2 2020
3X220201X2 2020
4X320201X3 2020
5X220201X2 2020
6X320201X3 2020
7X120201X1 2020
8X220201X2 2020
9X120201X1 2020
10X120201X1 2020
1X220211X2 2021
2X220211X2 2021
3X220211X2 2021
4X320211X3 2021
5X220211X2 2021
6X320211X3 2021
7X120211X1 2021
8X220211X2 2021
9X220211X2 2021
10X220211X2 2021

 

Ideally, the resulting table would be the following: 

Where each row is a count of the path an ID took over the course of the time series, based on SNKID. IE as the graph shows no one who was in X2 left X2 over the course of the years. 

 

For example: ID 1 went from being assigned X1 to being assigned X2 between 2019 and 2020, and is the only one who did so. Essentially, it is the same structure that as in this video: 

https://youtu.be/AK2KsJm_r2o?t=411

 

 

SourceTargetValue
X1 2019X1 2020    2
X1 2019X2 2020    1
X1 2019X3 2020    1
X2 2019X2 2020    3
X3 2019X1 2020   1
X3 2019X2 2020   1
X3 2019X3 2020   1
X1 2020X1 2021   1
X1 2020X2 2021   2
X2 2020X1 2021   0
X2 2020X2 2021   5
X3 2020X3 2021   2

 

Screenshot version:

 

 

The goal is to the create a Sankey Diagram that would look like this: (and is a rendition of the table above)

 

 

Thank you in advance! If more information is needed or this topic already exists, let me know. 

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi YeltsinC ,

    You can follow the below steps to get it, please find the details in the attachment.

    1. Create a calculated column to get the target SNKID

     

    Target = 
    CALCULATE (
        MIN ( 'Table'[SNKID] ),
        FILTER (
            'Table',
            'Table'[ID] = EARLIER ( 'Table'[ID] )
                && 'Table'[YEAR] > EARLIER ( 'Table'[YEAR] )
        )
    )

     

    2. Create a measure to get the sum of Value

     

    NValue = 
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', NOT ( ISBLANK ( 'Table'[Target] ) ) )
    )

     

    3. Create a Sankey chart (Source: SNKID   Destination: Target   Weight: NValue)

    Best Regards

3 Replies

  • Hi YeltsinC ,

     

    You definitely need to add more details on the logic behind calculating your 2nd table with SOURCE/TARGET using your original table.

    • YeltsinC's avatar
      YeltsinC
      Regular Visitor

      I added a bit more details to show what I mean exactly, hope it helps? 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi YeltsinC ,

    You can follow the below steps to get it, please find the details in the attachment.

    1. Create a calculated column to get the target SNKID

     

    Target = 
    CALCULATE (
        MIN ( 'Table'[SNKID] ),
        FILTER (
            'Table',
            'Table'[ID] = EARLIER ( 'Table'[ID] )
                && 'Table'[YEAR] > EARLIER ( 'Table'[YEAR] )
        )
    )

     

    2. Create a measure to get the sum of Value

     

    NValue = 
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', NOT ( ISBLANK ( 'Table'[Target] ) ) )
    )

     

    3. Create a Sankey chart (Source: SNKID   Destination: Target   Weight: NValue)

    Best Regards