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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dmytro_po
Frequent Visitor

DAX measure counting the most common sum of payments for a product

Hi!

Could you please help me to write a measure wich would calculate the most common sum of payments for each product.

image.png

 

For Product 1 I expest to see 300 and for Product 2 I expecet to see 500.

 

Thank you in advance for your help.

1 ACCEPTED SOLUTION

Hi @dmytro_po

 

Here is a one step solution. It combines the MEASURES above

 

see the file here

 

 

Go to Modelling Tab>>> New Table

 

MyTable =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            ADDCOLUMNS (
                SUMMARIZE (
                    TableName,
                    TableName[Product],
                    TableName[Customer],
                    "MostCommonCost", SUM ( TableName[Payment] )
                ),
                "CountPayments",
                VAR Currentsum =
                    CALCULATE ( SUM ( TableName[Payment] ) )
                VAR CurrentProduct =
                    CALCULATE ( SELECTEDVALUE ( TableName[Product] ) )
                RETURN
                    COUNTROWS (
                        FILTER (
                            FILTER (
                                ALL ( TableName[Product], TableName[Customer] ),
                                TableName[Product] = CurrentProduct
                            ),
                            CALCULATE ( SUM ( TableName[Payment] ) = Currentsum )
                        )
                    )
            ),
            "RankPayments", RANKX (
                ALL ( TableName[Product], TableName[Customer] ),
                CALCULATE ( [CountPayments] ),
                ,
                DESC,
                DENSE
            )
        ),
        [RankPayments] = 1
    ),
    TableName[Product],
    [MostCommonCost]
)

815.png


Regards
Zubair

Please try my custom visuals

View solution in original post

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

HI @dmytro_po

 

Try this solution

 

First Add a MEASURE that will count the Sum of Payments for each product

 

CountPayments =
VAR Currentsum =
    SUM ( TableName[Payment] )
VAR CurrentProduct =
    SELECTEDVALUE ( TableName[Product] )
RETURN
    COUNTROWS (
        FILTER (
            FILTER (
                ALL ( TableName[Product], TableName[Customer] ),
                TableName[Product] = CurrentProduct
            ),
            CALCULATE ( SUM ( TableName[Payment] ) = Currentsum )
        )
    )

You will get this

 

811.png

 

 

Now RANK the Count of Payments for each Product with this MEASURE

 

RankPayments =
RANKX (
    ALL ( TableName[Product], TableName[Customer] ),
    [CountPayments],
    ,
    DESC,
    DENSE
)

You will get

 

812.png

 


Regards
Zubair

Please try my custom visuals

Hi @Zubair_Muhammad,

thanks for your help.

 

However, as the end result, I would like to receive the following table:
image.png

 

Meaning, without the need of showing customers and sum of payments.

Hi @dmytro_po

 

Here is a one step solution. It combines the MEASURES above

 

see the file here

 

 

Go to Modelling Tab>>> New Table

 

MyTable =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            ADDCOLUMNS (
                SUMMARIZE (
                    TableName,
                    TableName[Product],
                    TableName[Customer],
                    "MostCommonCost", SUM ( TableName[Payment] )
                ),
                "CountPayments",
                VAR Currentsum =
                    CALCULATE ( SUM ( TableName[Payment] ) )
                VAR CurrentProduct =
                    CALCULATE ( SELECTEDVALUE ( TableName[Product] ) )
                RETURN
                    COUNTROWS (
                        FILTER (
                            FILTER (
                                ALL ( TableName[Product], TableName[Customer] ),
                                TableName[Product] = CurrentProduct
                            ),
                            CALCULATE ( SUM ( TableName[Payment] ) = Currentsum )
                        )
                    )
            ),
            "RankPayments", RANKX (
                ALL ( TableName[Product], TableName[Customer] ),
                CALCULATE ( [CountPayments] ),
                ,
                DESC,
                DENSE
            )
        ),
        [RankPayments] = 1
    ),
    TableName[Product],
    [MostCommonCost]
)

815.png


Regards
Zubair

Please try my custom visuals

@dmytro_po

 

 

Now you can add a visual level filter to get the RANK 1 i.e.most common sum of payments for each product.

 

813.png


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.