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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anon46
Frequent Visitor

Aggregated table with various column aggregations

Hi all,

 

Sorry if there have been similar asks in the past but cant find the exact solution that I am looking for 🙂

 

I am trying to create a new aggregated table based on a specific value where all of the columns have a different function, then add additional columns to it. The purpose is to track a metric via the KPI visual.

 

This is an example of the current Order table:

ColorOrderHours Date
YellowA5Jan-22
YellowB10Jan-22
YellowA22Feb-22
BlueA11Jan-22
BlueA77Jan-22
BlueB5Jan-22
BlueA8Feb-22
BlueA15Mar-22

 

Expected Result: (only return aggregated columns when Order = A)

ColorCount of Order AAvg Hours DatePeriod (New)Period Goal (New)
Yellow15Jan-22P1<=3
Yellow122Feb-22P2<=4
Blue244Jan-22P1<=3
Blue18Feb-22P2<=4
Blue115Mar-22P2<=4

 

logic: 

step 1: calculate Period based on defined months (jan = P1, feb/mar = p2)
step 2: calculate Period goal based on Period column (p1 goal avg hrs<=3, p2 goal avg hrs<=4)
Step 3:if Order = A, then return group by "Color", count of "Order", average "Hours", "Period Goal"

1 ACCEPTED SOLUTION

Hi,

I am not sure if I understood your question correctly, but could you please try the below?

 

New AGG Table =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( 'Order', 'Order'[Order], 'Order'[Color], 'Order'[Date] ),
            "@CountOrders", CALCULATE ( COUNTROWS ( 'Order' ) ),
            "@AvgHrs", CALCULATE ( AVERAGE ( 'Order'[Hours] ) ),
            "@Date", FORMAT ( 'Order'[Date], "mmm yy" ),
            "@Period",
                IF (
                    'Order'[Date] >= DATE ( 2022, 2, 1 )
                        && 'Order'[Date] <= DATE ( 2022, 3, 31 ),
                    "P1",
                    "P2"
                ),
            "@PeriodGoal",
                IF (
                    'Order'[Date] >= DATE ( 2022, 2, 1 )
                        && 'Order'[Date] <= DATE ( 2022, 3, 31 ),
                    "<=3",
                    "<=4"
                )
        ),
        'Order'[Order] = "A"
    ),
    'Order'[Color],
    [@CountOrders],
    [@AvgHrs],
    [@Date],
    [@Period],
    [@PeriodGoal]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

Please check the below DAX formula for creating a new table, and the attached pbix file.

 

New Agg Table = 
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( 'Order', 'Order'[Order], 'Order'[Color], 'Order'[Date] ),
            "@CountOrders", CALCULATE ( COUNTROWS ( 'Order' ) ),
            "@AvgHrs", CALCULATE ( AVERAGE ( 'Order'[Hours] ) ),
            "@Date", FORMAT ( 'Order'[Date], "mmm yy" ),
            "@Period",
                IF (
                    MONTH ( 'Order'[Date] ) = 1,
                    "P1",
                    IF ( MONTH ( 'Order'[Date] ) = 2 || MONTH ( 'Order'[Date] ) = 3, "P2" )
                ),
            "@PeriodGoal",
                IF (
                    MONTH ( 'Order'[Date] ) = 1,
                    "<=3",
                    IF ( MONTH ( 'Order'[Date] ) = 2 || MONTH ( 'Order'[Date] ) = 3, "<=4" )
                )
        ),
        'Order'[Order] = "A"
    ),
    'Order'[Color],
    [@CountOrders],
    [@AvgHrs],
    [@Date],
    [@Period],
    [@PeriodGoal]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi @Jihwan_Kim thanks for the quick reply! 🙂 I would need to create date ranges for @Period so I have changed "month" to "datesbetween" but I am getting an "Argument '3' in IF statment required" error. Below is what I am looking for using P2 as an example. Thoughts?

 

New Agg Table =

SUMMARIZE (

    FILTER (

        ADDCOLUMNS (

            SUMMARIZE ( 'Order', 'Order'[Order], 'Order'[Color], 'Order'[Date] ),

            "@CountOrders", CALCULATE ( COUNTROWS ( 'Order' ) ),

            "@AvgHrs", CALCULATE ( AVERAGE ( 'Order'[Hours] ) ),

            "@Date", FORMAT ( 'Order'[Date], "mmm yy" ),

            "@Period",

                IF (

                     datesbetween('Order'[Date],DATE(2022,02,01),DATE(2022,03,31))= 1,

                    "P2",

                ),

            "@PeriodGoal",

                IF ((

                     datesbetween('Order'[Date],DATE(2022,02,01),DATE(2022,03,31))= 1,

                    "<=3",

                )

        ),

        'Order'[Order] = "A"

    ),

    'Order'[Color],

    [@CountOrders],

    [@AvgHrs],

    [@Date],

    [@Period],

    [@PeriodGoal]

)

Hi,

I am not sure if I understood your question correctly, but could you please try the below?

 

New AGG Table =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( 'Order', 'Order'[Order], 'Order'[Color], 'Order'[Date] ),
            "@CountOrders", CALCULATE ( COUNTROWS ( 'Order' ) ),
            "@AvgHrs", CALCULATE ( AVERAGE ( 'Order'[Hours] ) ),
            "@Date", FORMAT ( 'Order'[Date], "mmm yy" ),
            "@Period",
                IF (
                    'Order'[Date] >= DATE ( 2022, 2, 1 )
                        && 'Order'[Date] <= DATE ( 2022, 3, 31 ),
                    "P1",
                    "P2"
                ),
            "@PeriodGoal",
                IF (
                    'Order'[Date] >= DATE ( 2022, 2, 1 )
                        && 'Order'[Date] <= DATE ( 2022, 3, 31 ),
                    "<=3",
                    "<=4"
                )
        ),
        'Order'[Order] = "A"
    ),
    'Order'[Color],
    [@CountOrders],
    [@AvgHrs],
    [@Date],
    [@Period],
    [@PeriodGoal]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.