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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
NicoH
Regular Visitor

Need help on DAX function

Hi everyone

I'm confused by the DAX function. I want to compare the budget and contract amount based on a table with the budget and contract info with the columns like BudgetID, Year, Budget Amount, ContractID, and Contract Amount.

Now the result like

c1.JPG

If removed SUM on budget amount,

 

 c12.JPG

 

 

 

 

I think it sums up the budget amount on different contracts.

So How to sum up the budget amount without the contract ID?

 

c2.JPG

 

 

18 REPLIES 18
NicoH
Regular Visitor

Hi  I tried your suggestion but no luck.

I have 2 tables: Budget and Contract. 

Budget Table

budget id | Year | budget amount

110 | 2021 | 4900

110 | 2022 | 4710.4 

 

Contract Table

BudgetID | contract ID | Year | contract amount

110          | c1               | 2021|  100

110          | c2               | 2021|  200

110          | c3               | 2022|  300

110          | c4               | 2022|  400

 

The result I want likes:

Budget ID | Year | Budget Amount | Contract Amount 

110           | 2021| 4900                   | 300

110           | 2022| 4710.4                | 700

 

Thanks in advance.

@voji

Hi, @NicoH 

 

I checked your model, your two tables have many-to-many relationships, what you need is to establish a master-slave table to improve the data model.

You can use distinct function to create single tables as slave table. According to the information you provide, you need to set a one-to-many relationship between budget id and year.

Like this:

Table = DISTINCT('Budget Table'[budget id])
Table 2 = DISTINCT('Budget Table'[Year])

vjaneygmsft_1-1650354489166.png

Then you need to use slave table budget id and year and master columns in visual.

 

vjaneygmsft_0-1650354216158.png

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

Hi Janey

Your solution works for the budget amount, but the contract amount does not work

Capture.JPG

vojtechsima
Super User
Super User

@NicoH Hi,
I am not sure I completely get your result, but you can use SUMX to iterate through the whole table and get the whole sum. 

SUMX('Table', [budget amount])

Please, if I get it wrong, share your copyable dataset and result, thank you.

Hi vojtechsima

Thanks for your tip.

Please find the sample data

budgetIDYeardepartmentbudgetAmount
1102021IT4900
1102022IT4700
2002021HR1000
2002022HR2000

 

budgetIDYearcontractIDcontractAmount
1102021c1100
1102022c2200
1102021c3300
1102022c4400
1102023c130
2002021HR-C1100
2002022HR-C1200
2002022HR-C2500

 

 

THe expected result

YearDepartmentBudgetAmountContractAmount
2021IT4900400
2022IT4700600

@NicoH 

vojtechsima_0-1650623191554.pngvojtechsima_1-1650623200200.png

ContracetAmountMeasure = 
CALCULATE(
    SUM(Contract[contractAmount]), USERELATIONSHIP(Budget[budgetID], Contract[budgetID]))

Could you let me know the linked key between Budget and Contract table?

 

Hi, @NicoH 
There is a non-active relationship between BudgetID and BudgetID ( I can then call it in the measure I sent).

But it's a many-to-many link.

@NicoH 
Well, yeah, it's definitely not Ideal, but it did achieve what you wanted.

I tried but the result is not correct.

demo1.JPG

Hi, @NicoH 
Did you use my measure to display the values in the table?

no

Hi, @NicoH 

 

vjaneygmsft_0-1650620009269.png

Are you sure that the columns on the dimension table are all placed in the table?

 

 

Sorry, here is the table structure.

Budget(budget id, year, department, budget amount)

Contract(budget id, year, contract id, contract amount)

 

@NicoH 

 

I mean, are you using the columns from the dimension table in visual? 

vjaneygmsft_0-1650622543692.png

 

Yes, I tried and it can calculate the budget amount correctly, but the contract amount did not.

Now I'm using the composite key for 2 tables: budgetid_year in budget table, budgetid_year_contractid in contract table. 

Hi, @NicoH 
did you check my newest post on this article?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors