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
arnabmit
Helper I
Helper I

Equally distribute expenses to agents

I have accounts in the attached files, as in the first table. I need to equally distribute the unallocated cost for the month to each agent as Addl. Expenses.

arnabmit_0-1652890287111.png

 

I am trying to create the second table using SUMMARIZECOLUMNS. I have the formula working in excel, but I am lost trying to replicate it in DAX.

 

=SUMIFS($D$2:$D$19,$B$2:$B$19,B25,$A$2:$A$19,"Unallocated")/COUNTA(UNIQUE(FILTER($A$2:$A$19,($B$2:$B$19=B25)*($A$2:$A$19<>"Unallocated"))))

 

Excel 

Thanks for any help in advance!

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@arnabmit 

 

New_Table = 
VAR _original_tbl = 
	FILTER(
		'Table',
		'Table'[Agent] <> "Unallocated"
	)
VAR _additional_expense = 
	CALCULATETABLE(
		ADDCOLUMNS(
			VALUES('Table'[Month]),
			"@Unallocated_Amount", CALCULATE(SUM('Table'[Amount]))
		),
		'Table'[Agent] = "Unallocated"
	)
VAR _new_tbl = 
	ADDCOLUMNS(
		SUMMARIZE(
			FILTER(
				'Table',
				'Table'[Agent] <> "Unallocated"
			),	
		'Table'[Agent],
		'Table'[Month]
		),
		"Type", "Addl. Expenses",
		"Amount", DIVIDE(
					SUMX(FILTER(_additional_expense, 'Table'[Month] = EARLIER('Table'[Month])), [@Unallocated_Amount]),
					CALCULATE(DISTINCTCOUNT('Table'[Agent]), REMOVEFILTERS('Table'[Agent]), 'Table'[Agent] <> "Unallocated")
				)
	)
RETURN

	UNION(
		_original_tbl,
		_new_tbl
	)

 




2022-05-09 22_36_04-Power BI Workspace Datasets License Permissions - Microsoft Power BI Community.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png  SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

3 REPLIES 3
SpartaBI
Community Champion
Community Champion

@arnabmit 

 

New_Table = 
VAR _original_tbl = 
	FILTER(
		'Table',
		'Table'[Agent] <> "Unallocated"
	)
VAR _additional_expense = 
	CALCULATETABLE(
		ADDCOLUMNS(
			VALUES('Table'[Month]),
			"@Unallocated_Amount", CALCULATE(SUM('Table'[Amount]))
		),
		'Table'[Agent] = "Unallocated"
	)
VAR _new_tbl = 
	ADDCOLUMNS(
		SUMMARIZE(
			FILTER(
				'Table',
				'Table'[Agent] <> "Unallocated"
			),	
		'Table'[Agent],
		'Table'[Month]
		),
		"Type", "Addl. Expenses",
		"Amount", DIVIDE(
					SUMX(FILTER(_additional_expense, 'Table'[Month] = EARLIER('Table'[Month])), [@Unallocated_Amount]),
					CALCULATE(DISTINCTCOUNT('Table'[Agent]), REMOVEFILTERS('Table'[Agent]), 'Table'[Agent] <> "Unallocated")
				)
	)
RETURN

	UNION(
		_original_tbl,
		_new_tbl
	)

 




2022-05-09 22_36_04-Power BI Workspace Datasets License Permissions - Microsoft Power BI Community.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png  SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Thank you so much! This worked perfectly! Now to try and learn more of DAX 😅

@arnabmit my pleasure 🙂

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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.