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
ccsnet
Frequent Visitor

Matching Totals Once Using Filters

Hi all,

 

I have a series of data which have a shared ID and I would like to show a total only once rather than matching to every line.

The following is the code I have and the result... does any one have a correct or better way of doing this ?

 

 

 

 

Sum Project Not Billed Milestones = 
CALCULATE(
    SUM(AT_ContractMilestones_NotBilled[amount]),
    FILTER(
        AT_ContractMilestones_NotBilled,
        AT_ContractMilestones_NotBilled[contractID] = AT_Projects[contractID]
    )
)

 

 

 

 

Capture.PNG

 

The above should only show £42.900.00 the first time its matched and no other times so the total at the bottom is correct.

 

There could be other matches through the data and those too should only be shown once.

 

Thanks In Advance

 

Terran

1 ACCEPTED SOLUTION
ccsnet
Frequent Visitor

Thank you all - for now I have gone with ...

 

This is because SUMX did not want to work and repeated the same number all the way down however I will go back but assume I could get a couple of missed numbers for now.

 

 

Sum Project Billed Milestones = 
CALCULATE(
    SUM(Autotask_ContractMilestones_Billed[amount]),
    FILTER(
        DISTINCT(Autotask_ContractMilestones_Billed[contractID]),
        Autotask_ContractMilestones_Billed[contractID] = Autotask_Projects[contractID]
    )
)

 

 

I will also have a look at the schema option which seems to be a good way forward too.

 

Thanks

 

T

View solution in original post

4 REPLIES 4
ccsnet
Frequent Visitor

Thank you all - for now I have gone with ...

 

This is because SUMX did not want to work and repeated the same number all the way down however I will go back but assume I could get a couple of missed numbers for now.

 

 

Sum Project Billed Milestones = 
CALCULATE(
    SUM(Autotask_ContractMilestones_Billed[amount]),
    FILTER(
        DISTINCT(Autotask_ContractMilestones_Billed[contractID]),
        Autotask_ContractMilestones_Billed[contractID] = Autotask_Projects[contractID]
    )
)

 

 

I will also have a look at the schema option which seems to be a good way forward too.

 

Thanks

 

T

v-tangjie-msft
Community Support
Community Support

Hi @ccsnet ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1707201986244.png

vtangjiemsft_1-1707201997022.png

(2) We can create a measure. 

Sum Project Not Billed Milestones = 
CALCULATE(
    SUM(AT_ContractMilestones_NotBilled[amount]),
    FILTER(
        AT_ContractMilestones_NotBilled,
        AT_ContractMilestones_NotBilled[contractID] =MAX(AT_Projects[contractID])
    )
)

(3) Then the result is as follows.

vtangjiemsft_2-1707202054779.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

123abc
Community Champion
Community Champion

To achieve the desired result of showing the total only once for each unique match, you can use the DISTINCT function in DAX. This function ensures that only distinct values are considered in the calculation. Here's how you can modify your DAX measure:

 

Sum Project Not Billed Milestones =
CALCULATE(
SUMX(
DISTINCT(AT_Projects[contractID]),
CALCULATE(
SUM(AT_ContractMilestones_NotBilled[amount]),
FILTER(
AT_ContractMilestones_NotBilled,
AT_ContractMilestones_NotBilled[contractID] = AT_Projects[contractID]
)
)
)
)

 

In this measure:

  • SUMX iterates over each distinct contractID in the AT_Projects table.
  • DISTINCT function ensures that each contractID is considered only once.
  • CALCULATE is used to perform the filtering and calculation for each distinct contractID.
  • FILTER is applied to filter the AT_ContractMilestones_NotBilled table based on the current contractID being iterated.
  • SUM calculates the sum of the filtered amount for each contractID.

This way, the total should only be shown once for each unique match, ensuring the correctness of the total at the bottom.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

some_bih
Super User
Super User

Hi @ccsnet usually, the best practice using Star schema is to show ID's based on some dimensions, like product id, or Customer ID.

Choose your Customer ID from your dimension table and check results. Check link for example





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors