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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
MarshalSK
Resolver I
Resolver I

Need a assistance with DAX calculation

Hi Folks, Need your experties, for DAX formula to get Sum of sales based on Col2.

 

I have provided Data, screen shot in Expected result (without filter and with Filter )

 

Sample Data:

MonthYearCol1Col2Col3Col4Sales 
Jan-23Pro1Sub Pro1A1Z1100 
Jan-23Pro1Sub Pro1A2Z1150 
Feb-23Pro2Sub Pro1B4Y1200 
Mar-23Pro3Sub Pro1B3Y2250 
Jan-23Pro1Sub Pro2B1Z1300 
Jan-23Pro1Sub Pro3C1Z1350 
Jan-23Pro1Sub Pro3C2Y1180 

 

MarshalSK_0-1708704345384.png

MarshalSK_1-1708704362674.png

MarshalSK_0-1708709164988.png

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MarshalSK ,

 

I suggest you to try code as below to create a measure.

Sum of Sales =
CALCULATE (
    SUM ( 'Table'[Sales] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[MonthYear] = MAX ( 'Table'[MonthYear] )
            && 'Table'[Col1] = MAX ( 'Table'[Col1] )
            && 'Table'[Col2] = MAX ( 'Table'[Col2] )
    )
)

Result is as below.

Without Filter

vrzhoumsft_0-1708932419536.png

Filter -> Exclude ->Col4-Z1

vrzhoumsft_1-1708932452330.png

Filter -> Exclude ->Col4-Y1,Col3-B4

vrzhoumsft_2-1708932557911.png

 

Best Regards,
Rico Zhou

 

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

12 REPLIES 12
Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Screenshot_1.pngScreenshot_2.png

Hi @Ahmedx , Thanks for the response and sorry expected result is slightly different which i missed out.

Sum of Sales should be based on Col1+Col2 (Expcted output as below screen shot)

MarshalSK_0-1708815008343.png

 

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur  my screen shots from excel and @Ahmedx  pbi file is pretty close, you can use the same . Thanks.

 

also let me know if anything specific you need to help me.

Hi,

Try this measure

m3 = CALCULATE([m1], ALLSELECTED(),GENERATE(VALUES('Table'[Col1]),VALUES('Table'[Col2])))

I have removed the criteria of Flag in the filter pane.

Hope this helps.

Ashish_Mathur_0-1708824984139.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur . really helpful. how to include two more columns in m3 ?

m3 = CALCULATE([m1], ALLSELECTED(),GENERATE(VALUES('Table'[Col1]),VALUES('Table'[Col2])))
GENERATE(VALUES('Table'[Col1]),VALUES('Table'[Col2]))

 

Anonymous
Not applicable

Hi @MarshalSK ,

 

I suggest you to try code as below to create a measure.

Sum of Sales =
CALCULATE (
    SUM ( 'Table'[Sales] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[MonthYear] = MAX ( 'Table'[MonthYear] )
            && 'Table'[Col1] = MAX ( 'Table'[Col1] )
            && 'Table'[Col2] = MAX ( 'Table'[Col2] )
    )
)

Result is as below.

Without Filter

vrzhoumsft_0-1708932419536.png

Filter -> Exclude ->Col4-Z1

vrzhoumsft_1-1708932452330.png

Filter -> Exclude ->Col4-Y1,Col3-B4

vrzhoumsft_2-1708932557911.png

 

Best Regards,
Rico Zhou

 

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

 

 

Good to know that.  You may write multiple GENERATE() functions but that would be cumbersome.  Someone else will help you with a better solution. 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks for the response. M2 should be 450 aggregation should happen on top of Col2. Results are not matching with screen shot.

Summary Table(Filter -> Exclude -> Col4-Z1)

pls try this

Screenshot_1.png

PijushRoy
Super User
Super User

Hi @MarshalSK 

Are you looking for a Dynamic title as per the FIlter selection?

If you looking for visual, please try Field Parameter
https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters

Let me know if that works for you


If your requirement is solved, please mark THIS ANSWER as SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.

Thanks
Pijush
Linkedin




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





hi @PijushRoy , dynamic DAX formula to get Sum of sales, column based on Col2.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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