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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
CW112358
Helper II
Helper II

How can I make Power Bi do this on the fly: in Excel its 2 sumif statements then subtract them?

So I had to change the info since its confidential but this should be close.  I want to know How much is still in Atlanta so the Destinations are positive numbers and the Source are negative numbers.  Atlanta = +1500 - 1000 +1000 -75 +75 = 1500.  This is only a small percent of the entire dataset so I want Power Bi to do this on the fly where I don't have to say = Atlanta.  I just want it to do it.  How can I do that?  Say I have 1 Million Destinations and Sources, how could I do it without doing it manually?

DestinationDest_dollarsSourceSource_dollars
Atlanta1500Seattle500
Bank500Atlanta1000
Atlanta1000Orlando3000
Bank3000Atlanta75
Atlanta75Seattle80
Bank80Birmingham1500
1 ACCEPTED SOLUTION
Anonymous
Not applicable

First, you create a dimension City and put all the cities found in both columns into it. Of course, only unique values must reside in the dimension. Then you have 2 fact tables: Destinations and Sources. Destinations is the first 2 columns. Sources - the 2 others. Now you connect the dimension City to the two facts. Filtering is City 1:* Destinations/Sources. This way you can slice by cities anyway you want.

 

Now you create 2 measures:

[Destination Dollars] = SUM( Destinations[Dest_dollars] )

[Source Dollars] = SUM( Source[Source_dollars] )

 

Your measure is:

[Leftover Dollars] = [Destination Dollars] - [Source Dollars]

 

Best

D

 

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

First, you create a dimension City and put all the cities found in both columns into it. Of course, only unique values must reside in the dimension. Then you have 2 fact tables: Destinations and Sources. Destinations is the first 2 columns. Sources - the 2 others. Now you connect the dimension City to the two facts. Filtering is City 1:* Destinations/Sources. This way you can slice by cities anyway you want.

 

Now you create 2 measures:

[Destination Dollars] = SUM( Destinations[Dest_dollars] )

[Source Dollars] = SUM( Source[Source_dollars] )

 

Your measure is:

[Leftover Dollars] = [Destination Dollars] - [Source Dollars]

 

Best

D

 

 

Anonymous
Not applicable

Hey @CW112358 ,

 

You can do a calculated measure: Atlanta Net = calculate(sum(dest_dollars),Destination = "Atlanta")-calculate(sum(source_dollars),Source = "Atlanta")

 

To explain what you're doing, you're summing all destination dollars that Destination = Atlanta and subtracting all source dollars for Source = Atlanta.

 

-Paul

That's one by one though, how can I make it general so that if I have 1 Million destinations that I want totals for, I don't have to write that many calcs?

Anonymous
Not applicable

Ah, I would just do some new summarized table then...

 

New Dest Table = SummerizeTable('Table Name',[Destination],"Destination Sum",sum(Destination Value))

New Source Table = SummerizeTable('Table Name',[Source],"SourceSum",sum(Source Value))

 

If you don't have a master list of locations, and if all locations (Source and Destination are in the Destination column...

New Dest Table = SummerizeTable('Table Name',[Destination])

 

then do two new calculated columns where you lookup the Destination Sum and SourceSum

Destination Sum = Lookupvalue("Destination Sum",'New Dest Table'[Destination],'Current Table'[Destination])

SourceSum = Lookupvalue("SourceSum",'New Source Table'[Source],'Current Table'[Source])

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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