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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
santoshlearner2
Resolver I
Resolver I

Top Product name

Dear All,

 

Stalwarts please help i just cannot get it. This i want for Top 1 & TOp 2 in card visuals. Pls note the results are based on the date selection and the measure for computing the sales figures

 

Measure to get Top 1 Values with the sub product and amount

 

Store: Name of the Stores

Main Product: Main Product Basket, which is further divided int sub product

Sub Product: Divisions of Main Products.

Daily Sales; Referred as [total sales]),

 

Measure  for top 1 Category =

CONCATENATEX (

    TOPN ( 1, VALUES ( sub product]),  [total sales]),

    sub product]),  & " - Rs " & format([total sales]), 0" & "  ($) "),

    ";"

 

 

)

 

The above gives me the product name along with the respective amount , this is in card visuals, now if I want to get name of the Stores for the above measure how do I get it, like Store 1 ( Name and value), store 2 Name and value ( in card visual)

 

Similarly of the above I want for Second Rank also.

 

Data is like this

 

Main ProductSub ProductStoreFinal sales  is from a measureDate
BikeTyresDelhi10031-01-2024
BikeChainmumbai15431-01-2024
BikeBucketgoa16031-01-2024
CarWindshieldbandra21031-01-2024
CarAccessoriesKhar23031-01-2024
CarPencilNagpur26031-01-2024
RulersSmallNorth10031-01-2024
RulersBigSouth15431-01-2024
RulersMediumChennai16031-01-2024
BikeTyresDelhi21030-01-2024
BikeChainmumbai23030-01-2024
BikeBucketgoa26030-01-2024
CarWindshieldbandra10030-01-2024
CarAccessoriesKhar11030-01-2024
CarPencilNagpur15530-01-2024
RulersSmallNorth15630-01-2024
RulersBigSouth21030-01-2024
RulersMediumChennai26030-01-2024
BikeTyresDelhi7828-01-2024
BikeChainmumbai45228-01-2024
BikeBucketgoa46028-01-2024
CarWindshieldbandra45028-01-2024
CarAccessoriesKhar13628-01-2024
CarPencilNagpur15628-01-2024
RulersSmallNorth85028-01-2024
RulersBigSouth123028-01-2024
RulersMediumChennai12028-01-2024
2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @santoshlearner2 
You can use the attached measures for the calculations :

Total Sales SUM('Table'[Sales])
Max Sales MAXX('table', [Total Sales])

Product with Max Sales

VAR MaxSales = [Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Main Product], 1),

    FILTER('table', [Total Sales] = MaxSales)

)

Store with Max Sales

VAR MaxSales = [Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Store], 1),

    FILTER('table', [Total Sales] = MaxSales)

)
Second Max Sales

VAR MaxSales = [Max Sales]

RETURN

MAXX(

    FILTER(

        'table',

        [Total Sales] < MaxSales

    ),

    [Total Sales]

)
Product with Second Max Sales

VAR SecondMaxSales = [Second Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Main Product], 1),

    FILTER('table', [Total Sales] = SecondMaxSales)

)

Store with Second Max Sales

VAR SecondMaxSales = [Second Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Store], 1),

    FILTER('table', [Total Sales] = SecondMaxSales)

)

Ritaf1983_0-1722601836153.png

And then concatenate the results according your needs.
The pbix is attached 

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

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

v-xinruzhu-msft
Community Support
Community Support

Hi,

Thanks for the solution @Ritaf1983  offered, and i want to offer some more information for user to refer to.

hello @santoshlearner2 , you can refer to the following solution.

The sample data is the same as you provided, create the following measures.

 

Sales = SUM('Table'[Final sales])
Top1 =
VAR a =
    TOPN (
        2,
        SUMMARIZE (
            ALLSELECTED ( 'Table' ),
            [Store],
            'Table'[Main Product],
            'Table'[Sub Product],
            [Date],
            "Sales", [Sales]
        ),
        [Sales], DESC
    )
VAR b =
    MAXX ( a, [Sales] )
RETURN
    CONCATENATEX (
        FILTER ( a, [Sales] = b ),
        [Store] & "(" & [Sub Product] & " " & "$" & [Sales] & ")"
    )
Top2 =
VAR a =
    TOPN (
        2,
        SUMMARIZE (
            ALLSELECTED ( 'Table' ),
            [Store],
            'Table'[Main Product],
            'Table'[Sub Product],
            [Date],
            "Sales", [Sales]
        ),
        [Sales], DESC
    )
VAR b =
    MINX ( a, [Sales] )
RETURN
    CONCATENATEX (
        FILTER ( a, [Sales] = b ),
        [Store] & "(" & [Sub Product] & " " & "$" & [Sales] & ")"
    )

 

Then put the top measures to the card visual.

Output

vxinruzhumsft_0-1722823889439.png

 

Best Regards!

Yolo Zhu

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

4 REPLIES 4
santoshlearner2
Resolver I
Resolver I

Dear Power BI Greats,

 

Wasted weeks to find a solution  just not getting it. I want to create card like this , wanted card visuals

 

1) For eg if a person selects a date, then in the card, the name of the  top selling product should be displayed alongwith the amount,  then in the next to it i have another card which will show which is the store who sold maximum units on that date for that  product, like this i have two more cards showing top 2 and top 3 names of the stores ( for that product) for eg

 

Byke sales : Rs 10 cr, then Store 1 - Rs 50 lacs, store 2: 15 lacs, store 3: 10 lacs

 

2) Then i want to show second best selling product, which will in a visual card, then similar to point one in card visual the name and amount of the store selling the maximum units of that products

 

Car sales : Rs 3 cr, then Store 1 - Rs 45 lacs, store 2: 25 lacs, store 3: 15 lacs.

 

Basicaly i have measure which does daily computation of price / units sold based on each day values


You may suggest Any other method to show,

 

Thanks in advance to everyone,

 

Thank you

Hi, @santoshlearner2 

Can you provide some simple sample data that does not contain private data? So that you can write the corresponding DAX expression according to your table structure. In addition, you can refer to the following tutorial to get Top N, and then you can use & to connect the store name and sales corresponding to Top N.

https://community.fabric.microsoft.com/t5/Desktop/card-with-top-product-by-sales/td-p/2510766

https://community.fabric.microsoft.com/t5/Desktop/Card-with-two-Top-N-FIlters/m-p/3871591


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

v-xinruzhu-msft
Community Support
Community Support

Hi,

Thanks for the solution @Ritaf1983  offered, and i want to offer some more information for user to refer to.

hello @santoshlearner2 , you can refer to the following solution.

The sample data is the same as you provided, create the following measures.

 

Sales = SUM('Table'[Final sales])
Top1 =
VAR a =
    TOPN (
        2,
        SUMMARIZE (
            ALLSELECTED ( 'Table' ),
            [Store],
            'Table'[Main Product],
            'Table'[Sub Product],
            [Date],
            "Sales", [Sales]
        ),
        [Sales], DESC
    )
VAR b =
    MAXX ( a, [Sales] )
RETURN
    CONCATENATEX (
        FILTER ( a, [Sales] = b ),
        [Store] & "(" & [Sub Product] & " " & "$" & [Sales] & ")"
    )
Top2 =
VAR a =
    TOPN (
        2,
        SUMMARIZE (
            ALLSELECTED ( 'Table' ),
            [Store],
            'Table'[Main Product],
            'Table'[Sub Product],
            [Date],
            "Sales", [Sales]
        ),
        [Sales], DESC
    )
VAR b =
    MINX ( a, [Sales] )
RETURN
    CONCATENATEX (
        FILTER ( a, [Sales] = b ),
        [Store] & "(" & [Sub Product] & " " & "$" & [Sales] & ")"
    )

 

Then put the top measures to the card visual.

Output

vxinruzhumsft_0-1722823889439.png

 

Best Regards!

Yolo Zhu

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

Ritaf1983
Super User
Super User

Hi @santoshlearner2 
You can use the attached measures for the calculations :

Total Sales SUM('Table'[Sales])
Max Sales MAXX('table', [Total Sales])

Product with Max Sales

VAR MaxSales = [Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Main Product], 1),

    FILTER('table', [Total Sales] = MaxSales)

)

Store with Max Sales

VAR MaxSales = [Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Store], 1),

    FILTER('table', [Total Sales] = MaxSales)

)
Second Max Sales

VAR MaxSales = [Max Sales]

RETURN

MAXX(

    FILTER(

        'table',

        [Total Sales] < MaxSales

    ),

    [Total Sales]

)
Product with Second Max Sales

VAR SecondMaxSales = [Second Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Main Product], 1),

    FILTER('table', [Total Sales] = SecondMaxSales)

)

Store with Second Max Sales

VAR SecondMaxSales = [Second Max Sales]

RETURN

CALCULATE(

    FIRSTNONBLANK('table'[Store], 1),

    FILTER('table', [Total Sales] = SecondMaxSales)

)

Ritaf1983_0-1722601836153.png

And then concatenate the results according your needs.
The pbix is attached 

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

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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