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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
kasife
Helper V
Helper V

Growth percentage by category

 

Hi guys.

How could I get the following result? For example, I would like to calculate the difference and growth in percentage of the 1st Closing Forecast in relation to the 2nd Closing Forecast, the 2nd Closing Forecast in relation to the 3rd Closing Forecast, but I am not using any calendar table, only table category.

 

Example:
1º Closing Forecast (735)
2º Closing Forecast (651)
Difference = 84

growth in percentage = - 12%

kasife_0-1675275573047.png

 

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

Hi @kasife ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1675308484743.png

(2)Go into the power query editor and copy and paste the code into the "Advanced Editor".

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjy0S8E5J784My9dwS2/KDU5sbhESUfJ3NhUKVYnWskIu7SZqSFY2hiHtIUZWNoEh+GWQN2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Value", Int64.Type}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Category", "Category - Copy"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Category - Copy", Splitter.SplitTextByDelimiter("º Closing Forecast", QuoteStyle.Csv), {"Category - Copy.1", "Category - Copy.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Category - Copy.1", Int64.Type}, {"Category - Copy.2", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Category - Copy.2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Category - Copy.1", "Category - Index"}})
in
    #"Renamed Columns"

(3) We can create a calculated column.

Column = 
IF (
    LOOKUPVALUE ( 'Table'[Value], 'Table'[Category - Index], 'Table'[Category - Index] - 1 )
        = BLANK (),
    0,
    (
       'Table'[Value]
            - LOOKUPVALUE ('Table'[Value], 'Table'[Category - Index], 'Table'[Category - Index] - 1)
    )
        / LOOKUPVALUE ( 'Table'[Value], 'Table'[Category - Index], 'Table'[Category - Index] - 1 )
)

(4) Then the result is as follows.

vtangjiemsft_1-1675308644515.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

2 REPLIES 2
v-tangjie-msft
Community Support
Community Support

Hi @kasife ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1675308484743.png

(2)Go into the power query editor and copy and paste the code into the "Advanced Editor".

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjy0S8E5J784My9dwS2/KDU5sbhESUfJ3NhUKVYnWskIu7SZqSFY2hiHtIUZWNoEh+GWQN2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Value", Int64.Type}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Category", "Category - Copy"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Category - Copy", Splitter.SplitTextByDelimiter("º Closing Forecast", QuoteStyle.Csv), {"Category - Copy.1", "Category - Copy.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Category - Copy.1", Int64.Type}, {"Category - Copy.2", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Category - Copy.2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Category - Copy.1", "Category - Index"}})
in
    #"Renamed Columns"

(3) We can create a calculated column.

Column = 
IF (
    LOOKUPVALUE ( 'Table'[Value], 'Table'[Category - Index], 'Table'[Category - Index] - 1 )
        = BLANK (),
    0,
    (
       'Table'[Value]
            - LOOKUPVALUE ('Table'[Value], 'Table'[Category - Index], 'Table'[Category - Index] - 1)
    )
        / LOOKUPVALUE ( 'Table'[Value], 'Table'[Category - Index], 'Table'[Category - Index] - 1 )
)

(4) Then the result is as follows.

vtangjiemsft_1-1675308644515.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Its working. Thanks @v-tangjie-msft 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.