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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
naveenpadala
Regular Visitor

Compare TopN Doctor Specialty's visits for current financial year to previous financial years

I have Financial specialties, which have patient visits(PPD) for each Fiscal Year(FY). I want to get the TopN Financial specialties for current FY (i.e 2023 present) and compare the same Financial specialties for previous FY (i.e, 2022, 2021 etc). When i tried the TopN for previous FY, it doesnot show the same Financial specialites. 

Please find the raw data and expected results sheet in below link:
https://docs.google.com/spreadsheets/d/1-DeCrhc8KCcpycchOymxBueAsJvub3Tu/edit?usp=share_link&ouid=11... 

1 ACCEPTED SOLUTION
alena2k
Resolver IV
Resolver IV

hi @naveenpadala 

You can Pivot year column in Power Query and then use TopN for the year you need.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jVhLb+NGDP4rQc57GA45Q/LYdoOgwOaBbbfAItiD6qixAMcOZKdo/n0pO1KGsmQvcglEzpD8+PExfni4/Fyvd9Xq8tMl55yIlKP9H0PEyx+fHi5/WVf1drest81mtXl6M1EOHFI46MCcjhICH3TCXud++7ZYNtWu7cSYo4kVKR9U4vs1j21/QSjPTggOhu/MaNt9gEQQglAs73MmE3QKLFIG97V6HFyOgCwxBpxTEMwiCjF5n0eRpxiSgEbv/5GSRa/oYvmtaj9sISahrOUlTk5BoqCW56/rdd1Wq4v7tlrsmkW9N4PEHKCMaEKNydIR+ttm4sKUFDNxqTQwJ+eYKGRml5zOTLV+vLip/mtWq80/1aKxL3+8tk/1gQWGuB1y7g1XAgNRQlByLKp2yyFhkg3p3iP8OZsxZciK4MNon6tdfy0ko0oMjrwjjQzADLEM9nPzZIA1/9aFLQDMaqk+SYXIRqsg6XTNASVKiVyKJk1il6QopWtXVfvp4nazrffA/LlsN9WuI0cmySH8jKYFy72H73n49uXm7vbuy9319z0gqJx93ygzZZmUlBOW3l891+b0evF2cVM/Notm3TFxrwAyrwCHyEDnVaQDaV6MRBRcdf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Text = true]) in type table [#"Financial Specialty Grouping" = _t, PPD = _t, FY = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Financial Specialty Grouping", type text}, {"PPD", Int64.Type}, {"FY", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [FY] <> null),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Filtered Rows", {{"FY", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Filtered Rows", {{"FY", type text}}, "en-US")[FY]), "FY", "PPD", List.Sum)
in
    #"Pivoted Column"

Note, you will need to clean data for the records with missing FY - I simply filtered it before pivoting.

Here is a link to download .pbix file.

View solution in original post

1 REPLY 1
alena2k
Resolver IV
Resolver IV

hi @naveenpadala 

You can Pivot year column in Power Query and then use TopN for the year you need.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jVhLb+NGDP4rQc57GA45Q/LYdoOgwOaBbbfAItiD6qixAMcOZKdo/n0pO1KGsmQvcglEzpD8+PExfni4/Fyvd9Xq8tMl55yIlKP9H0PEyx+fHi5/WVf1drest81mtXl6M1EOHFI46MCcjhICH3TCXud++7ZYNtWu7cSYo4kVKR9U4vs1j21/QSjPTggOhu/MaNt9gEQQglAs73MmE3QKLFIG97V6HFyOgCwxBpxTEMwiCjF5n0eRpxiSgEbv/5GSRa/oYvmtaj9sISahrOUlTk5BoqCW56/rdd1Wq4v7tlrsmkW9N4PEHKCMaEKNydIR+ttm4sKUFDNxqTQwJ+eYKGRml5zOTLV+vLip/mtWq80/1aKxL3+8tk/1gQWGuB1y7g1XAgNRQlByLKp2yyFhkg3p3iP8OZsxZciK4MNon6tdfy0ko0oMjrwjjQzADLEM9nPzZIA1/9aFLQDMaqk+SYXIRqsg6XTNASVKiVyKJk1il6QopWtXVfvp4nazrffA/LlsN9WuI0cmySH8jKYFy72H73n49uXm7vbuy9319z0gqJx93ygzZZmUlBOW3l891+b0evF2cVM/Notm3TFxrwAyrwCHyEDnVaQDa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) meta [Serialized.Text = true]) in type table [#"Financial Specialty Grouping" = _t, PPD = _t, FY = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Financial Specialty Grouping", type text}, {"PPD", Int64.Type}, {"FY", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [FY] <> null),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Filtered Rows", {{"FY", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Filtered Rows", {{"FY", type text}}, "en-US")[FY]), "FY", "PPD", List.Sum)
in
    #"Pivoted Column"

Note, you will need to clean data for the records with missing FY - I simply filtered it before pivoting.

Here is a link to download .pbix file.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors