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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AnthonyJoseph
Resolver III
Resolver III

Calculate number of sum of values if Entity exists in all the selected years

Hello Community,

 

I am trying to create a measure that calculates sum of values based on a condition (i.e. only it the Entity exists in all of the selected years). 
For example: From the below table When the years "2022" and "2021" are selected the calculation/graph should display the sum of values only for "Meat and Fruit" entities (Veggies will not be included as there is no entry for Veggies in 2022). Below are the tables:

 

Unit table:

EntityYearunit
Fruit2022100
Fruit2021200
Fruit2020500
Veggies2021100
Veggies202040
Meat2022150
Meat2021250

 

Description Table:

EntityDescriptionYearValues
FruitApple202210
FruitPear202220
FruitMango202215
FruitOrange202225
FruitGrape202230
FruitPapaya202110
FruitApple202115
FruitPear202110
FruitMango202115
FruitOrange202160
FruitGrape202140
FruitKiwi202150
VeggiesCarrot202130
VeggiesBeans202120
VeggiesCucumber202140
VeggiesCabbage202110
VeggiesCarrot202010
VeggiesBeans202010
VeggiesCucumber202010
VeggiesPeas20205
VeggiesCorn20205
MeatChicken202150
MeatDuck202140
MeatPork202150
MeatTurkey202160
MeatLamb202150
MeatChicken202240
MeatGoat202220
MeatPork202230
MeatTurkey202260

 

Expected output:

 

AnthonyJoseph_0-1673943713769.png

I m not sure if there is anyway to achieve this but appereciate any response.

 

Thanks,

AnthonyJoseph

1 ACCEPTED SOLUTION

@AnthonyJoseph , that's odd... anyway, we can add a check for a Year slicer: ISFILTERED ( 'Year'[Year] ).

ValuesFiltered =
VAR yearsAmt = COUNTROWS ( ALLSELECTED ( 'Year'[Year] ) )
VAR c_entity = SELECTEDVALUE ( 'Description_Table'[Entity] )
VAR t =
    FILTER (
        Unit,
        Unit[Entity] = c_entity
            && Unit[Year] IN ALLSELECTED ( 'Year'[Year] )
    )
RETURN
    IF (
        ISFILTERED ( 'Year'[Year] ),
        IF ( COUNTROWS ( t ) = yearsAmt, [ValuesAmt], BLANK () )
    )

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

12 REPLIES 12
DimaMD
Solution Sage
Solution Sage

Hi @AnthonyJoseph try it

 

Amount_value = 
 CALCULATE( SUM('Description Table'[Values]), ALLNOBLANKROW('Description Table'[Year]))

Screenshot_29.jpg

 


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

Hi @DimaMD I m not able to replicate the output. I tried using the measure. Please if you can share the pbix or provide guidance that will be much helpful.

 

AnthonyJoseph_0-1673967146819.png

 

Thanks,

AnthonyJoseph

Hi, @AnthonyJoseph I corrected the measurement and connections, please see the attachment

Amount_value = 
VAR _Amount =
 CALCULATE( SUM('Description Table'[Values]), ALLSELECTED('Yeаr'[Year]))
 return
 IF( ISFILTERED('Description Table'[Year]),BLANK(), _Amount)


Screenshot_29.jpg


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

@AnthonyJoseph file


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com
ERD
Super User
Super User

Hello @AnthonyJoseph,

I believe there are multiple ways to achieve that. You can try these measures:

ValuesAmt = SUM('Description'[Values])
ValuesFiltered = 
VAR yearsAmt = COUNTROWS ( ALLSELECTED ( 'Year'[Year] ) )
VAR c_entity = SELECTEDVALUE ( 'Description'[Entity] )
VAR t =
    FILTER (
        Unit,
        Unit[Entity] = c_entity && Unit[Year] IN ALLSELECTED ( 'Year'[Year] )
    )
RETURN 
    IF (
        ISFILTERED ( 'Year'[Year] ),
        IF ( COUNTROWS ( t ) = yearsAmt, [ValuesAmt], BLANK () ),
        [ValuesAmt]
    )

ERD_0-1673947299294.png

ERD_1-1673947467946.png

 

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thanks @ERD. When all the years and all entties are selected the graph should display only blank graph but its displaying all the 3 categories. Please can you help me with this.

If you can please attach the pbix it will be easy for me.

Thanks,
AnthonyJoseph

@AnthonyJoseph ,

It's easy, just change the return part in the measure:

ValuesFiltered = 
VAR yearsAmt = COUNTROWS ( ALLSELECTED ( 'Year'[Year] ) )
VAR c_entity = SELECTEDVALUE ( 'Description'[Entity] )
VAR t =
    FILTER (
        Unit,
        Unit[Entity] = c_entity && Unit[Year] IN ALLSELECTED ( 'Year'[Year] )
    )
RETURN 
    IF ( COUNTROWS ( t ) = yearsAmt, [ValuesAmt], BLANK () )

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thanks @ERD . Unfortunately the above measure gives blank when more than one year is selected. i.e. when I select 2021 and 2022 the graph should be descriptions that are realted to "Fruits" and "Meat" but its is giving blank.

AnthonyJoseph_0-1674025007686.png

The request is to provide the list of "Description items" that are common across the selected years (can be of any year selection combination- 2020 and 2021, 2021 and 2022, 2020 and 2022, all three years etc..). Please can you share your thoughts on how to achieve this logic?

 

Thanks,

AnthonyJoseph

@AnthonyJoseph , what table do you use in your slicer? I've added a screenshot showing that there is a dimension table - Year. I used it in a slicer (connected to your data tables). That's why you see blanks.

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thanks for clarifying @ERD . However,  "Fruit" entity is shown always irrespective of year selection. Also, Blank is not appearing when all years are selected.

 

I have attached the file here please can you help.

 

AnthonyJoseph_0-1674027129549.png

Thanks,

AnthonyJoseph

 

@AnthonyJoseph , that's odd... anyway, we can add a check for a Year slicer: ISFILTERED ( 'Year'[Year] ).

ValuesFiltered =
VAR yearsAmt = COUNTROWS ( ALLSELECTED ( 'Year'[Year] ) )
VAR c_entity = SELECTEDVALUE ( 'Description_Table'[Entity] )
VAR t =
    FILTER (
        Unit,
        Unit[Entity] = c_entity
            && Unit[Year] IN ALLSELECTED ( 'Year'[Year] )
    )
RETURN
    IF (
        ISFILTERED ( 'Year'[Year] ),
        IF ( COUNTROWS ( t ) = yearsAmt, [ValuesAmt], BLANK () )
    )

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Привіт, З Західної України
Слава Україні!!!!


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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