Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
YeltsinC
Regular Visitor

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:

 

YeltsinC_0-1624293784844.png

 

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

 

YeltsinC_0-1624293477025.png

 

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

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

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)

yingyinr_0-1624433337951.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

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)

yingyinr_0-1624433337951.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Pragati11
Super User
Super User

Hi @YeltsinC ,

 

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

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.