Forum Discussion

masplin's avatar
masplin
Icon for Impactful Individual rankImpactful Individual
1 year ago
Solved

Struggling with getting a total from component column

Hi. i have a model with sales opportunties table and another table which records the date at which an opportuntiy moves past a stage in the process (qualify, devlop, propose, quote,close). Sometimes...
  • OwenAuger's avatar
    1 year ago

    Hi masplin 

    A quick fix would be to create another measure Won Value £ summed that iterates over SalesStageSort, summing Won Value £ for each row, and use that in your visuals:

     

    Won Value £ summed = 
    SUMX (
        SalesStageSort,
        [Won Value £]
    )

     

    or you could include the code from the original measure wrapped in CALCULATE (or some variation of this):

     

    Won Value £ summed = 
    SUMX (
        SalesStageSort,
        CALCULATE (
            // Original Measure Expression here
        )
    )

     

    Alternatively, you could create a "dynamic segmentation"-style measure similar to the last measure shown in DAX Patterns: Dynamic Segmentation.

    Here's how I would write it given my understanding of your model:

     

    Won Value £ (Dynamic Segmentation) = 
    VAR Maxdate = MAX ( DateTable[Date] )
    VAR DateRange = VALUES ( DateTable[Date] )
    VAR OpportunityLatestStage =
        CALCULATETABLE (
            INDEX (
                1,
                SUMMARIZE ( 'Sales Process', 'Sales Process'[Stage Rank], 'Sales Process'[Sales Stage At], Opportunity[Opportunity ID] ),
                ORDERBY ( 'Sales Process'[Stage Rank], ASC ),
                DEFAULT,
                PARTITIONBY ( Opportunity[Opportunity ID] )
            ),
            KEEPFILTERS ( TREATAS ( DateRange , Opportunity[Close Date] ) ), -- Close Date filter
            KEEPFILTERS ( 'Sales Process'[Completed Date] <= Maxdate ), -- Completed Date filter
            ALLSELECTED ( ) -- Optimization to reuse cached results. OpportunityLatestStage table should be computed once.
        )
    VAR OpportunitiesInStage =
        FILTER (
            OpportunityLatestStage,
            VAR StageForOpportunity =
                FILTER ( SalesStageSort, SalesStageSort[Sales Stage] = 'Sales Process'[Sales Stage At] )
            VAR IsOpportunityInStage = NOT ISEMPTY ( StageForOpportunity )
            RETURN
                IsOpportunityInStage
        )
    VAR Result =
        CALCULATE (
            SUM ( Opportunity[Act Value Won £] ),
            KEEPFILTERS ( OpportunitiesInStage )
        )
    RETURN
        Result

     

    Do any of these work for you?