Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

DAX Getting Same Grand Total Amount in Each Row

If I select 'Current Hierarchy'[Sales Code] and 'Quota Results'[Location Quota], it displays the correct results row by row.  But I have onother table called 'BCP' which has a [Sales Code].  When I s...
  • DataNinja777's avatar
    1 year ago

    Anonymous ,

     

    The issue of getting the same grand total in each row is typically caused by filter context not propagating correctly between tables. Even though you created a relationship between 'BCP'[Sales Code] and 'Current Hierarchy'[Sales Code], it seems the filter from 'BCP'[Sales Code] is not influencing 'Quota Results'[Location Quota].

     

    To fix this, ensure the relationship is active and propagates correctly through the model. If the relationship alone doesn’t resolve the issue, use DAX functions to enforce the filter. For instance, you can use the TREATAS function to apply 'BCP'[Sales Code] as a filter on 'Current Hierarchy'[Sales Code], ensuring it affects the quota calculation:

     

    Location Quota Adjusted = 
    CALCULATE(
        SUM('Quota Results'[Location Quota]),
        TREATAS(
            VALUES('BCP'[Sales Code]),
            'Current Hierarchy'[Sales Code]
        )
    )
    

    Alternatively, if the mapping is direct, you can use LOOKUPVALUE to fetch the corresponding Location Quota for each Sales Code in 'BCP'. Validate the filter context with a simple test measure and ensure relationships are correctly configured for your data model.

     

    Best regards,

  • DataNinja777's avatar
    DataNinja777
    1 year ago

    Hi Anonymous 

     

    I'm glad it worked 😀.

     

    Now, moving onto your 2nd follow up question, to solve the issue of aligning 'BCP'[Date Closed] with 'Quota Results'[Month Year], you need to ensure the date granularity matches and filters propagate correctly. Since 'BCP'[Date Closed] has specific dates and 'Quota Results'[Month Year] uses monthly granularity, use TREATAS in your DAX measure to bridge the gap. Here's the updated measure:

    Location Quota Adjusted by Date = 
    CALCULATE(
        SUM('Quota Results'[Location Quota]),
        TREATAS(
            VALUES('BCP'[Sales Code]),
            'Current Hierarchy'[Sales Code]
        ),
        TREATAS(
            VALUES('Calendar 2'[Month Year]), 
            'Quota Results'[Month Year]
        )
    )
    

    Ensure that 'Calendar 2'[Month Year] matches the format of 'Quota Results'[Month Year], such as "MMM-YY". This measure applies filters for both the Sales Code and the corresponding month based on 'BCP'[Date Closed]. If issues persist, double-check that relationships are active and formats are consistent.

     

    Best regards,