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
PowerBiDax
Regular Visitor

Calculate Group by 2 others columns

Hello,

I need to create a measure using DAX that has the sum of the qty, I should take the max date of the table that is between two other dates (Date Slicer) based on the column name, For exemple if the selected date of the slicer is between  24/6/2020 and 20/3/2021

PowerBiDax_0-1673977482296.png

the result should be 

PowerBiDax_1-1673977732813.png

Thank you.

 

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1673978970698.png

 

Jihwan_Kim_1-1673979877409.png

 

 

Expected result Date: =
CALCULATE (
    SELECTEDVALUE ( 'Calendar'[Date] ),
    INDEX (
        1,
        SUMMARIZE ( ALLSELECTED ( Data ), 'Name'[Name], 'Calendar'[Date], Data[Qty] ),
        ORDERBY ( 'Calendar'[Date], DESC, Data[Qty], DESC ),
        KEEP,
        PARTITIONBY ( 'Name'[Name] )
    )
)

 

Expected result Qty: = 
CALCULATE (
    SUM(Data[Qty]),
    INDEX (
        1,
        SUMMARIZE ( ALLSELECTED ( Data ), 'Name'[Name], 'Calendar'[Date], Data[Qty] ),
        ORDERBY ( 'Calendar'[Date], DESC, Data[Qty], DESC ),
        KEEP,
        PARTITIONBY ( 'Name'[Name] )
    )
)

 

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.

Thank you a lot for your help, but I don't know why it's not working for me 

PowerBiDax_1-1673980675623.png

 

 

Hi,

just in case, please check the version of the power bi desktop.

 

December 2022

 

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.

Now the pbix works, but this is not what I have to get, when selecting the date(in the slicer) I need to get  the qty of the max date of the name that is between the selected date, for exp for B I need to take the Qty=50(it correspond to the max date (Sat, 30 Jan 2021 00:00:00 between the selected date of the slicer) 

PowerBiDax_0-1674042049086.png

The Expected result date is correct date, now I have to take the qty that corresponds to it. 

 

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.