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

October 28 & 29: Experts share their secrets on how to pass the Fabric Analytics Engineer certification exam—live. Learn more

Reply
PBI_37
Helper I
Helper I

DAX Formula

Hi everyone,

 

I created a DAX formula which returns a flag « X » on certain rows.

Now I would like to calculate the sum of the rows that have the flag by year. I created this formula but it doesn't work :

Total Sales with Flag = CALCULATE([Total Sales], FILTER(Sales, [Flag] = "X"))

 

PBI_37_0-1721465887177.png

 

Here the link of PBI file :

https://drive.google.com/file/d/1ejt-aQ2J04GRP-zBc9ygPAwaM59zQ_Gc/view?usp=sharing

 

Thank you for your help.

3 ACCEPTED SOLUTIONS
Wilson_
Super User
Super User

Hi PBI_37,

 

I was able to return the correct value, if I understood your intention.

 

Wilson__0-1721482079952.png

 

Try this measure instead for your Total Sales with Flag:

Total Sales with Flag = 
VAR YearMonth =
SUMMARIZE (
    'Calendar',
    'Calendar'[Year], 'Calendar'[Month Name]
)
VAR SalesbyMonth =
ADDCOLUMNS (
    YearMonth,
    "@Flag", [Flag]
)
VAR FilteredYearMonth =
FILTER (
    SalesbyMonth,
    [@Flag] = "X"
)
VAR Result =
SUMX (
    FilteredYearMonth,
    [Total Sales]
)

RETURN Result

 

The reason mine works and yours doesn't is because when you put your flag in the filter condition in your measure, it is looking at every sales line and checking if the sales on that order are greater than 4,000. Mine forces it to make the check at the year/month level (like you have in your matrix).


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




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

Proud to be a Super User!





View solution in original post

ThxAlot
Super User
Super User

Assez facile,

ThxAlot_0-1721484341710.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This measure works

Total Sales with Flag = CALCULATE([Total Sales],FILTER(VALUES('Calendar'[Month Name]),[Total Sales]>4000))

Ashish_Mathur_0-1721519337594.png

 


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

View solution in original post

9 REPLIES 9
PBI_37
Helper I
Helper I

Thank you @Ashish_Mathur , @ThxAlot@Wilson_ 

Your soutions work perfectly.

You are welcome.


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

Thanks for the update, happy to help! 😄




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

Proud to be a Super User!





Ashish_Mathur
Super User
Super User

Hi,

This measure works

Total Sales with Flag = CALCULATE([Total Sales],FILTER(VALUES('Calendar'[Month Name]),[Total Sales]>4000))

Ashish_Mathur_0-1721519337594.png

 


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

Assez facile,

ThxAlot_0-1721484341710.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Wilson_
Super User
Super User

Hi PBI_37,

 

I was able to return the correct value, if I understood your intention.

 

Wilson__0-1721482079952.png

 

Try this measure instead for your Total Sales with Flag:

Total Sales with Flag = 
VAR YearMonth =
SUMMARIZE (
    'Calendar',
    'Calendar'[Year], 'Calendar'[Month Name]
)
VAR SalesbyMonth =
ADDCOLUMNS (
    YearMonth,
    "@Flag", [Flag]
)
VAR FilteredYearMonth =
FILTER (
    SalesbyMonth,
    [@Flag] = "X"
)
VAR Result =
SUMX (
    FilteredYearMonth,
    [Total Sales]
)

RETURN Result

 

The reason mine works and yours doesn't is because when you put your flag in the filter condition in your measure, it is looking at every sales line and checking if the sales on that order are greater than 4,000. Mine forces it to make the check at the year/month level (like you have in your matrix).


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




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

Proud to be a Super User!





mickey64
Super User
Super User

For your reference.

Please try this measure below.

    Total Sales with Flag = CALCULATE(SUM('Sales'[Total Sales]), FILTER(Sales, 'Sales'[Flag] = "X"))

Thank you @mickey64 but it doesn't work

How about this ?

Total Sales with Flag = CALCULATE([Total Sales], FILTER(SUMMARIZE(Sales,Sales[Year],Sales[Month Name],Sales[Total Sales],Sales[Flag]), [Flag] = "X"))

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

October NL Carousel

Fabric Community Update - October 2024

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