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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Saud_Jilani
New Member

I want to create a dax formula which returns the best performing day in Power Bi.

To simplify I need to use the Max formula as Max(1,2,3) where it returns 3. But it is not possible, so is there is a way around it. So I have sales in a column and day name in the other. I need the day with the highest total sales. Here is the way I tried to achieve it:

Best Day =
            Var Sun = CALCULATE(SUM('Sales (2)'[Sales]), 'Dax Calendar'[Day Name] = "Sunday")

            Var Mon = CALCULATE(SUM('Sales (2)'[Sales]), 'Dax Calendar'[Day Name] = "Monday")

            Var Tues = CALCULATE(SUM('Sales (2)'[Sales]), 'Dax Calendar'[Day Name] = "Tuesday")

            Var Wed = CALCULATE(SUM('Sales (2)'[Sales]), 'Dax Calendar'[Day Name] = "Wednesday")

            Var Thurs = CALCULATE(SUM('Sales (2)'[Sales]), 'Dax Calendar'[Day Name] = "Thursday")

            Var Fri = CALCULATE(SUM('Sales (2)'[Sales]), 'Dax Calendar'[Day Name] = "Friday")

            Var Sat = CALCULATE(SUM('Sales (2)'[Sales]), 'Dax Calendar'[Day Name] = "Saturday")

RETURN

MAX(Sun,Mon,Tues,Wed,Thurs,Fri,Sat)

2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @Saud_Jilani 
You can create 2 measures :

1 for highest sales :

Highest sales =
MAXX(
    SUMMARIZE (
        Sales,
      'calendar'[Date],
        "Total sales", SUM('Sales'[sales_])
    ),
    [Total sales]
)
 
second for the day of highest sales 
Highest day =
VAR vTable = VALUES('calendar'[WeekDay] )
VAR highestSales = [Highest sales]
VAR Keepmin = FILTER( vTable, [Highest sales] = highestSales )
VAR HighestDay = IF( highestSales >0, CONCATENATEX( Keepmin, [WeekDay], ", "))
RETURN

HighestDay
 
Result:
Ritaf1983_0-1721017356046.png

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

Hi @Saud_Jilani 
For the highest second day, you can use these formulas :

Highest sales 2 =

MINX( TOPN(2,

    SUMMARIZE (
        Sales,
      'calendar'[WeekDay],
        "Total sales",SUM('Sales'[sales_])
    ),[Total sales],DESC)
,[Total sales])
 
And for the day :
Highest day 2 =
VAR vTable = VALUES('calendar'[WeekDay] )
VAR highestSales2 = [Highest sales 2]
VAR Keepmin = FILTER( vTable, [Highest sales 2] = highestSales2 )
VAR HighestDay2 = IF( highestSales2 >0, CONCATENATEX( Keepmin, [WeekDay], ", "))
RETURN

HighestDay2
Result:
Ritaf1983_0-1721026168026.png

The updated 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

5 REPLIES 5
Ritaf1983
Super User
Super User

Hi @Saud_Jilani 
You can create 2 measures :

1 for highest sales :

Highest sales =
MAXX(
    SUMMARIZE (
        Sales,
      'calendar'[Date],
        "Total sales", SUM('Sales'[sales_])
    ),
    [Total sales]
)
 
second for the day of highest sales 
Highest day =
VAR vTable = VALUES('calendar'[WeekDay] )
VAR highestSales = [Highest sales]
VAR Keepmin = FILTER( vTable, [Highest sales] = highestSales )
VAR HighestDay = IF( highestSales >0, CONCATENATEX( Keepmin, [WeekDay], ", "))
RETURN

HighestDay
 
Result:
Ritaf1983_0-1721017356046.png

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

Thanks @Ritaf1983 , its perfect.
Any idea on how to get the 2nd best day as well? 

Hi @Saud_Jilani 
For the highest second day, you can use these formulas :

Highest sales 2 =

MINX( TOPN(2,

    SUMMARIZE (
        Sales,
      'calendar'[WeekDay],
        "Total sales",SUM('Sales'[sales_])
    ),[Total sales],DESC)
,[Total sales])
 
And for the day :
Highest day 2 =
VAR vTable = VALUES('calendar'[WeekDay] )
VAR highestSales2 = [Highest sales 2]
VAR Keepmin = FILTER( vTable, [Highest sales 2] = highestSales2 )
VAR HighestDay2 = IF( highestSales2 >0, CONCATENATEX( Keepmin, [WeekDay], ", "))
RETURN

HighestDay2
Result:
Ritaf1983_0-1721026168026.png

The updated 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
rajendraongole1
Super User
Super User

Hi @Saud_Jilani - create below measure to calculate the highest total sales, I hope you have a day name column in your dataset.

 Measure:

 

Best Day Sales =
MAXX(
VALUES('DaySales'[Day Name]), -- Iterate over each unique day name
CALCULATE(SUM('DaySales'[Total Sales])) -- Calculate total sales for each day
)

 

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thanks, @rajendraongole1, it works well.
How can modify it to result as:
The Highest day is "x" with the sales"$x" and the 2nd highest day is "y" with the sales "$y" . 
By "$x" I refer the amount, and "x" refers to the corresponding day. 

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!

December 2024

A Year in Review - December 2024

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