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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Pier2
Resolver I
Resolver I

Sum a mesure with conditions

 

Hello,

 

I try to sum the value of a mesure (not a calculated column) for a giving year and category of company.

 

At the end, the companies of the same category, for the same year, should have the same total.  Filtering and removing the filter doesn't work. Otherwise, I end up with exact individual value of each company.How can I achieve that?

 

 

CompanyCategory
AATech
BBBank
CCBank
DDBank

 

CompanyYearRevenus
AA2023500
DD2024600
BB2024300
CC2024200

 

CompanyMesure_value_A Year 2024
AA1
BB5
CC8
DD2

 

 

Result expected,  for company of same category, for 2024

 

CompanySum by category of Mesure_value_A
BB15
CC15
DD15

 

1 ACCEPTED SOLUTION

The solution is:

    CALCULATE(
        SUMX(
            FILTER(
                ALL(tblEntreprise),  -- Retirer les filtres sur les entreprises
                tblEntreprise[lngEntrepriseCategorie] = categorieSelectionnee  -- Limiter aux entreprises de la catégorie sélectionnée
            ),
            [m026_indiceVCICapitauxPropres]  -- Calculer la mesure pour chaque entreprise
        ),
        CalendrierAnnuel[Année fiscale] = anneeSelectionnee  -- Appliquer le filtre sur l'année
    )

View solution in original post

5 REPLIES 5
v-linhuizh-msft
Community Support
Community Support

Thanks for the reply from DataNinja777.

 

Hi @Pier2 ,

 

Based on your description, I created relationships for these tables:

vlinhuizhmsft_0-1738833202275.png

 

Create a measure:

Measure = SUMX(FILTER(ALLEXCEPT('Revenue','Category'[Category]),'Revenue'[Year]=MAX('Revenue'[Year])),[Mesure_value_A Year])

 

Use the company field from the table on the many-side as the column for the visual.

vlinhuizhmsft_1-1738833271358.png

Best Regards,
Zhu

 

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

Hello @v-linhuizh-msft ,

 

Unfortunately, your proposition isn't the solution yet. I still working on it.


To help understad anyone reading this post, I add a picture of the relations between the table. It may surely help.

The table Mesures is filled with all kind of measures that works right.

 

Pier2_0-1739040806269.png

 

DataNinja777
Super User
Super User

Hi @Pier2 ,

 


To achieve the desired result, you need a DAX measure that sums Mesure_value_A for all companies in the same Category and Year while ensuring that each company in the same category receives the same total. The key is to remove the filter on Company while keeping the filters on Category and Year. You can use the CALCULATE function along with ALLEXCEPT to achieve this:

Sum by Category of Mesure_value_A =
CALCULATE(
    SUM('YourTable'[Mesure_value_A]),
    ALLEXCEPT('YourTable', 'YourTable'[Category], 'YourTable'[Year])
)

This measure ensures that the sum is calculated over all companies within the same category and year, effectively distributing the same total to each company in that group. When applied to a table visualization, companies belonging to the same category in the given year will display identical totals.

 

Best regards,

Hello @DataNinja777 ,

Thanks for your help. I've try your formula, but I'm sorry to say that it didn't work.

SUM doesn't mix with a mesure.

The year and the category are in two different tables and cannot fit together in AllExcept. 

AllExcept and other type function to remove a filter doesn't help, so far.

We are probably close to the right answer.

Here's the real code that works so far. The results are wrong but I got something.

VAR somme_x= 
CALCULATE(
    SUMX(Mesures,[m026_indiceVCICapitauxPropres]),
    tblEntreprise[lngEntrepriseCategorie]=categorieSelectionnee,
    CalendrierAnnuel[Année fiscale]= anneeSelectionnee
)

 I got the list of companies but with their individual mesure value.

The solution is:

    CALCULATE(
        SUMX(
            FILTER(
                ALL(tblEntreprise),  -- Retirer les filtres sur les entreprises
                tblEntreprise[lngEntrepriseCategorie] = categorieSelectionnee  -- Limiter aux entreprises de la catégorie sélectionnée
            ),
            [m026_indiceVCICapitauxPropres]  -- Calculer la mesure pour chaque entreprise
        ),
        CalendrierAnnuel[Année fiscale] = anneeSelectionnee  -- Appliquer le filtre sur l'année
    )

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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