Forum Discussion

Niels_83's avatar
Niels_83
Copper Contributor
Nov 17, 2025

power query/ dax measure , multiple conditions/ multiple answers

I have loaded multiple tables in power query

table of revenue per category:

categoryrevenue
EM01                           86.000
EM02                           68.000
EM03                           93.000
EM04                           87.000
EM05                              6.000
EM06                           96.000
EM07                           87.000
EM08                           54.000

 

table of share per category per accountmanager:

employeeaccountmanagershare accountmanager
EM01AM175%
EM01AM225%
EM02AM1100%
EM03AM2100%
EM04AM3100%
EM05AM260%
EM05AM340%
EM06AM1100%
EM07AM150%
EM07AM350%
EM08AM2100%

 

Note: in same cases (EM01, EM05, EM07) multiple accountmanagers are in charge for a category. Total of share per category is always 100%.

How to organize in power query to connect both tables to get table of revenue per per category per accountmanager? Use measure? Which? Or other solution?

 

Answer (in pivot table) should be:

employeeAM1AM2AM3total
EM01     64.500     21.500               -       86.000
EM02     68.000               -                 -       68.000
EM03               -       93.000               -       93.000
EM04               -                 -       87.000     87.000
EM05               -          3.600        2.400        6.000
EM06     96.000               -                 -       96.000
EM07     43.500               -       43.500     87.000
EM08               -       54.000               -       54.000

 

6 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    Power Query variant with Grand Total

    let
        Source = Table.Join(Shares, {"employee"}, Revenue, {"category"}, JoinKind.LeftOuter),
        AddShared = Table.AddColumn(Source, "Shared", each [share accountmanager]*[revenue], Currency.Type),
        SelectColumns = Table.SelectColumns(AddShared,{"employee", "accountmanager", "Shared"}),
        PivotManagers = Table.Pivot( SelectColumns,
            List.Distinct(SelectColumns[accountmanager]), "accountmanager", "Shared", List.Sum),
        AddTotal = Table.AddColumn( PivotManagers,
            "Total",
            each List.Sum ( List.Skip( Record.FieldValues(_) ) ),
            Currency.Type),
        GrandTotal = Table.FromColumns(
            {{"Grand Total"}} &
            List.Transform( List.Skip( Table.ToColumns( AddTotal ) ),
                (q) => {List.Sum(q)} ), Table.ColumnNames(AddTotal)
        ),
        Result = AddTotal & GrandTotal,
        DeclareType = Table.TransformColumnTypes( Result,
            List.Zip({ {Table.ColumnNames( Result ){0}}, {type text} } ) &
            List.Transform( List.Skip( Table.ColumnNames( Result ) ), (q) => { q, Currency.Type } )
        )
    
    in
        DeclareType
    • Niels_83's avatar
      Niels_83
      Copper Contributor

      And what if there are multiple rows per EM in revenue table? Then it's not possible to make a connections between revenue table and AM table.

      • SergeiBaklan's avatar
        SergeiBaklan
        Diamond Contributor

        You may use measure like

        Shared :=
        VAR TotalRevenue =
            SUMMARIZE (
                Revenue,
                Revenue[category],
                "Revenue", SUM ( Revenue[revenue] )
            )
        VAR AddShares =
            ADDCOLUMNS (
                CROSSJOIN (
                    TotalRevenue,
                    Shares
                ),
                "ToTake",
                    Revenue[category] = Shares[employee]
            )
        VAR Filtered =
            FILTER (
                AddShares,
                [ToTake]
            )
        VAR KeepColumns =
            SELECTCOLUMNS (
                Filtered,
                "Employee", [employee],
                "Manager", [accountmanager],
                "Revenue", [revenue],
                "Share, %", [share accountmanager]
            )
        VAR Result =
            ADDCOLUMNS (
                KeepColumns,
                "Shared",
                    [Revenue] * [Share, %]
            )
        RETURN
            SUMX (
                Result,
                [Shared]
            )

        For Power Query only no changes are required

Resources