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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
manojsubram
Frequent Visitor

Dynamic Dax measure to filter out data when the sum of amount is zero based on date selected

Hello All,

 

I need to create a measure to use as a filter to dynamically show data only when the sum of the amount is not zero for a group. For an selected date range, If the sum of the amount is zero for an group, then do not want to show the group in the report.

 

I’ve the data as shown below. Have Group 1, Group 2 and Group 3. I need to show only the groups when the sum of amount is not zero for the selected range.

 

Input Data

 

Date

Group

Amount

12/15/2023

Group1

150

12/16/2023

Group1

-150

12/15/2023

Group2

50

12/16/2023

Group2

80

12/17/2023

Group2

-130

12/15/2023

Group3

60

12/15/2023

Group4

50

12/16/2023

Group4

-40

 

Expected Output in the report.

 

Case 1

When Date Selected <=12/15/2023, I would like to see the below result in the report.

 

Date

Group

Amount

12/15/2023

Group1

150

12/15/2023

Group2

50

12/15/2023

Group3

60

12/15/2023

Group4

50

 

Case 2

When Date Selected <=12/16/2023, Result will have the data for Group 2, Group 3 , Group 4 for 12/15/2023 and 12/16/2023. Sum of the amount for Group 1 on 12/15/2023 and 12/16/2023 is zero, need to filter out in the report.

 

Date

Group

Amount

12/15/2023

Group2

50

12/16/2023

Group2

80

12/15/2023

Group3

60

12/15/2023

Group4

50

12/16/2023

Group4

-40

 

I really appreciate any suggestion on meeting this requirement. 

1 ACCEPTED SOLUTION

@Ashish_Mathur 

Thanks for your response.

This mesures works, but when i apply the date filter showing wrong values. I've updated the measure as shown below and getting the result as expected. 

calculate(sum(Fact_Table[Amount]),allselected(Dim_Date[Date]))

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

Just write this meaure and filter with the condtiion >0

Measure =- sum(Data[Amount])


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

@Ashish_Mathur 

Thanks for the response. 

 

I've to use this measure in a table visual as shown below. It has the Group Name and Date. Group 1 (150 + -150) and Group 2(-50 + -50 + 80) have the net amount is zero and should not listed in the table visual. When i use the Measure =- sum(Data[Amount]), Group 1 and Group 2 are showing in the visual.

 

I would appreciate for any recommendations. 

 

 

manojsubram_0-1714363501089.png

 

Thank you!

 

Hi,

Assuming the Date field in the slicer and table visual has been dragged from the Calendar Table, write this measure

Measure = calculate(sum(Data[Amount]),all(calendar[date]))

Ths should now show 0 in the first 5 rows of the table visual.  Filter this meaure with the criteria of <>0

Hope this helps.


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

@Ashish_Mathur 

Thanks for your response.

This mesures works, but when i apply the date filter showing wrong values. I've updated the measure as shown below and getting the result as expected. 

calculate(sum(Fact_Table[Amount]),allselected(Dim_Date[Date]))
ddpl
Solution Sage
Solution Sage

@manojsubram Hi
Create measure as per below and use it as filter in filter panel as per below snap.

Zero1 =
     var grp =
             MAX('Table'[Group])
     var zero =
             CALCULATE(SUM('Table'[Amount]),
             'Table'[Group] = grp ,ALLSELECTED('Table'[Date]))
     return
     zero
ddpl_0-1713941592930.png

@ddpl - Thanks for your response.

1. This measure is working fine for a small set of data. I've a large dataset of 12 million and getting an error "Visual exceeding the available resourses. Please let know if you've any recommendation. 

2. When we try to normalize the data model as shown below and update the measure to use the dimension. This is not giving the expected result. 

 

Zero2 =
     var grp =
             MAX(Dim_Group[Group Name])
     var zero =
             CALCULATE(SUM(Fact_Table[Amount]),
             Dim_Group[Group Name] = grp ,ALLSELECTED(Dim_Date[Date]))
     return
          zero

 

manojsubram_0-1714355213992.png

 

v-linyulu-msft
Community Support
Community Support

Hi,@manojsubram 

First, as I understand it, your requirement is that if the data is within the time interval of your desired data and the sum of the data within the group is zero, it is not displayed, otherwise it is displayed. If my understanding is wrong, please give me your relative opinion:

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1713941139238.png

2.I then created a slicer based on your time data that allows you to easily select a time interval:

vlinyulumsft_1-1713941158875.png

3.I then created the following measure for filtering whether the data in the group sums to 0 or not:

Measure = 
var zero1=CALCULATE(SUM(zero[Amount]),FILTER(ALLSELECTED(zero),'zero'[Group]=MAX('zero'[Group])))
return if(zero1=0,1,0)

4.Here's my final result, which I hope meets your requirements.

vlinyulumsft_2-1713941212361.pngvlinyulumsft_3-1713941221428.png

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

Best Regards,

Leroy Lu

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

@v-linyulu-msft 

Thanks for your response.

1. This measure is working fine for a small set of data. I've a large dataset of 12 million and getting an error "Visual exceeding the available resourses. Please let know if you've any recommendation. 

2. When we try to normalize the data model as shown below and update the measure to use the dimension. Measure is throwing up error. 

 

manojsubram_1-1714355942882.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.