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

Trying to ma the difference between 2 columns in different tables in a measure

Hi, 

I have 2 tables 

1) Sales tables (daily)

2) Forecast tables (monthly)

(Both are link to my look up tables :  product, customer, calendar)

 

I am trying to have a measure that would help my compare the total per different caterogies (1st step is the SalesRep) 

But every measure i've tried only calculate totals and i cannot use my different filter

Ex :  Want to compare total of sales at the end of may per REP vs their forecast.   Then i'll want to compare client by client... etc... so it has to be dynamic based on the date. 

 

Any tips on how to write this ?  I am really new with Dax and struggling a bit here. 

 

2 ACCEPTED SOLUTIONS

@PeterVachon ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Need to try with data

View solution in original post

v-yangliu-msft
Community Support
Community Support

Hi  @PeterVachon ,

This is the data I created:

Sales tables:

v-yangliu-msft_0-1621928571398.png

Forecast tables:

v-yangliu-msft_1-1621928571400.png

look up tables:

v-yangliu-msft_2-1621928571404.png

Here are the steps you can follow:

1. Create measure.

alltoal =
var _select=
SELECTEDVALUE('look up table'[date])
return
CALCULATE(SUM('Sales tables'[amount]),FILTER(ALL('Sales tables'),'Sales tables'[Customer]=MAX('Sales tables'[Customer])&&'Sales tables'[Month]=MONTH(_select)))
Forecastamount =
var _select=SELECTEDVALUE('look up table'[date])
return
CALCULATE(SUM('Forecast tables'[Amount]),FILTER(ALL('Forecast tables'),'Forecast tables'[monthly]=MONTH(_select)&&'Forecast tables'[Customer]=MAX('Forecast tables'[Customer])))
Flag =
IF(MAX('Sales tables'[date]) in SELECTCOLUMNS('look up table',"1",[date]),1,0)
Flag1 =
IF(MAX('Forecast tables'[monthly]) in SELECTCOLUMNS('look up table',"1",MONTH('look up table'[date])) ,1,0)

2. Put [Flag] and [Flag1] into the Filter of the corresponding visual object respectively, is=1, apply filter.

v-yangliu-msft_3-1621928571405.png

3. Put [date] of the look up table table into the slicer, according to the selected date, to display the corresponding total sales and monthly forecast value, and compare

4. Result:

v-yangliu-msft_4-1621928571410.png

 

 

Best Regards,

Liu Yang

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

View solution in original post

5 REPLIES 5
v-yangliu-msft
Community Support
Community Support

Hi  @PeterVachon ,

This is the data I created:

Sales tables:

v-yangliu-msft_0-1621928571398.png

Forecast tables:

v-yangliu-msft_1-1621928571400.png

look up tables:

v-yangliu-msft_2-1621928571404.png

Here are the steps you can follow:

1. Create measure.

alltoal =
var _select=
SELECTEDVALUE('look up table'[date])
return
CALCULATE(SUM('Sales tables'[amount]),FILTER(ALL('Sales tables'),'Sales tables'[Customer]=MAX('Sales tables'[Customer])&&'Sales tables'[Month]=MONTH(_select)))
Forecastamount =
var _select=SELECTEDVALUE('look up table'[date])
return
CALCULATE(SUM('Forecast tables'[Amount]),FILTER(ALL('Forecast tables'),'Forecast tables'[monthly]=MONTH(_select)&&'Forecast tables'[Customer]=MAX('Forecast tables'[Customer])))
Flag =
IF(MAX('Sales tables'[date]) in SELECTCOLUMNS('look up table',"1",[date]),1,0)
Flag1 =
IF(MAX('Forecast tables'[monthly]) in SELECTCOLUMNS('look up table',"1",MONTH('look up table'[date])) ,1,0)

2. Put [Flag] and [Flag1] into the Filter of the corresponding visual object respectively, is=1, apply filter.

v-yangliu-msft_3-1621928571405.png

3. Put [date] of the look up table table into the slicer, according to the selected date, to display the corresponding total sales and monthly forecast value, and compare

4. Result:

v-yangliu-msft_4-1621928571410.png

 

 

Best Regards,

Liu Yang

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

PeterVachon
Frequent Visitor

To better explain,  I've tried splitting up my formual to see what is going on.

1st part of my formula isn't working correctly it returns the TOTAL sales YTD and doesn't spread per REP as i would like it to in my matrix, 

 

Measure = CALCULATE(sumx(FILTER('Sales','Sales'[invoicedt] >= 2021-01-01),'Sales'[NET]))
 
It's probably not the right operator... calculatetable also deliver the sames results. 
amitchandak
Super User
Super User

@PeterVachon , Not very clear on the issue. Becuase if you have calendar table, joined to both tables, then you can compare actual and forecast values monthly 

 

if sales rep is not a common dimesion, then you can not compare that.

 

If handeling date is an issue refer

Distributing/Allocating the Monthly Target(Convert to Daily Target): Measure ( Daily/MTD): https://community.powerbi.com/t5/Community-Blog/Power-BI-Distributing-Allocating-the-Monthly-Target-...

What i am trying to do is write a measure that with take my Total Sales -  Forecast and be able to spread it out per REP or customer.  Depending on how I present my Matrix/Table.   If i only use a quick measure it doesn't work and doesn't spread correctly. 

 

But, I keep getting only the TOTAL.

 

My filter regardings the dates is working well... no worry. 

 

BTW : Thx for your link this will come up handy real soon 😉

@PeterVachon ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Need to try with data

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.