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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Jansco
Helper I
Helper I

Help Creating a calculated row

Given a table like this:

 

Product Person Month Value

ASteveJanuary1
ASteveFebruary2
ASteveMarch3
AJamesJanuary4
AJamesFebruary5
BJamesMarch6
BSteveJanuary7
BSteveMarch9

 

and a Matrix like this

 

Product Person January February March

ASteve123
AJames456
BSteve7 9

 

and the condition, if Month = January, sum January and multiply by .05, if Month = February sum February values and multiply by .75, if Month=March, sum March values and multiply by .25...

 

Is this possible?  I would like the result to look like this:

 

Product Person January February March

ASteve123
AJames456
BSteve7 9
calc 0.65.254.5
TOTAL 12.612.2522.5

 

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

Hi @Jansco ,

 

One sample for your reference. Please check the following steps as below.

 

1. Duplicated the fact table in power query , then pviot value column.

Capture.PNG

M code for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQouSS1LBdJuqUlFpYlFlUCmkVKsDqqkb2JRcgaQNobLeCXmphaD6TyoLhMMOSQjTcGSTkiSMCPN4DIwyxBGmmPIwXRZKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [A = _t, Steve = _t, January = _t, #"1" = _t]),
    #"Demoted Headers" = Table.DemoteHeaders(Source),
    #"Renamed Columns" = Table.RenameColumns(#"Demoted Headers",{{"Column1", "Product"}, {"Column2", "Name"}, {"Column3", "Month"}, {"Column4", "Value"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Value", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Month]), "Month", "Value", List.Sum)
in
    #"Pivoted Column"

2. Create a calculated calculated column in fact table.

 

Column =
IF (
    'Table1 (2)'[Month] = "January",
    CALCULATE (
        SUM ( 'Table1 (2)'[Value] ),
        ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
    ) * 0.05
        / CALCULATE (
            COUNTROWS ( 'Table1 (2)' ),
            ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
        ),
    IF (
        'Table1 (2)'[Month] = "February",
        CALCULATE (
            SUM ( 'Table1 (2)'[Value] ),
            ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
        ) * 0.75
            / CALCULATE (
                COUNTROWS ( 'Table1 (2)' ),
                ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
            ),
        IF (
            'Table1 (2)'[Month] = "March",
            CALCULATE (
                SUM ( 'Table1 (2)'[Value] ),
                ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
            ) * 0.25
                / CALCULATE (
                    COUNTROWS ( 'Table1 (2)' ),
                    ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
                )
        )
    )
)

3. Enter a new table and create three calculated column in the new table.

January = CALCULATE(SUM('Table1 (2)'[Column]),FILTER('Table1 (2)','Table1 (2)'[Month]="January"))
February = CALCULATE(SUM('Table1 (2)'[Column]),FILTER('Table1 (2)','Table1 (2)'[Month]="February"))
March = CALCULATE(SUM('Table1 (2)'[Column]),FILTER('Table1 (2)','Table1 (2)'[Month]="March"))

2.PNG

 

4. Union table1 and table2.

Table = UNION(Table1,Table2)

3.PNG

 

Regards,

Frank

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

View solution in original post

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @Jansco ,

 

One sample for your reference. Please check the following steps as below.

 

1. Duplicated the fact table in power query , then pviot value column.

Capture.PNG

M code for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQouSS1LBdJuqUlFpYlFlUCmkVKsDqqkb2JRcgaQNobLeCXmphaD6TyoLhMMOSQjTcGSTkiSMCPN4DIwyxBGmmPIwXRZKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [A = _t, Steve = _t, January = _t, #"1" = _t]),
    #"Demoted Headers" = Table.DemoteHeaders(Source),
    #"Renamed Columns" = Table.RenameColumns(#"Demoted Headers",{{"Column1", "Product"}, {"Column2", "Name"}, {"Column3", "Month"}, {"Column4", "Value"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Value", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Month]), "Month", "Value", List.Sum)
in
    #"Pivoted Column"

2. Create a calculated calculated column in fact table.

 

Column =
IF (
    'Table1 (2)'[Month] = "January",
    CALCULATE (
        SUM ( 'Table1 (2)'[Value] ),
        ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
    ) * 0.05
        / CALCULATE (
            COUNTROWS ( 'Table1 (2)' ),
            ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
        ),
    IF (
        'Table1 (2)'[Month] = "February",
        CALCULATE (
            SUM ( 'Table1 (2)'[Value] ),
            ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
        ) * 0.75
            / CALCULATE (
                COUNTROWS ( 'Table1 (2)' ),
                ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
            ),
        IF (
            'Table1 (2)'[Month] = "March",
            CALCULATE (
                SUM ( 'Table1 (2)'[Value] ),
                ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
            ) * 0.25
                / CALCULATE (
                    COUNTROWS ( 'Table1 (2)' ),
                    ALLEXCEPT ( 'Table1 (2)', 'Table1 (2)'[Month] )
                )
        )
    )
)

3. Enter a new table and create three calculated column in the new table.

January = CALCULATE(SUM('Table1 (2)'[Column]),FILTER('Table1 (2)','Table1 (2)'[Month]="January"))
February = CALCULATE(SUM('Table1 (2)'[Column]),FILTER('Table1 (2)','Table1 (2)'[Month]="February"))
March = CALCULATE(SUM('Table1 (2)'[Column]),FILTER('Table1 (2)','Table1 (2)'[Month]="March"))

2.PNG

 

4. Union table1 and table2.

Table = UNION(Table1,Table2)

3.PNG

 

Regards,

Frank

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

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors