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
davidi4524
Helper III
Helper III

calculate target vs total sale

hi, i need to calculate target vs total sale per date

i have two tables:

1. target

columns: 

datebranchtargetkey
6/19/201745241006.19.20174524
6/20/201745242006.20.20174524
6/21/201745243006.21.20174524
6/22/201745244006.22.20174524
07/01/2017452410007.1.20174524

 

 

2.sales

columns: 

datebranchsalekey
6/19/20174524106.19.20174524
6/19/20174524206.19.20174524
6/19/20174524306.19.20174524
6/19/20174524406.19.20174524
6/19/20174524506.19.20174524
6/20/20174524306.20.20174524
6/20/20174524406.20.20174524
6/20/20174524506.20.20174524
6/20/20174524606.20.20174524
6/20/20174524706.20.20174524
6/20/20174524806.20.20174524
6/20/20174524906.20.20174524
6/21/2017452416.21.20174524
6/21/2017452426.21.20174524
6/21/2017452436.21.20174524
6/21/2017452446.21.20174524
6/21/2017452456.21.20174524
6/21/2017452466.21.20174524
6/22/20174524206.22.20174524
6/22/20174524406.22.20174524
6/22/20174524606.22.20174524
6/22/20174524806.22.20174524
6/22/201745241006.22.20174524

i need to show on power bi :

 

datebranchtargetkeytotal saledelta
6/19/201745241006.19.2017452415050
6/20/201745242006.20.20174524420220
6/21/201745243006.21.2017452421-279
6/22/201745244006.22.20174524300-100
07/01/2017452410007.1.20174524null0

 

how can i do it? i tried to do in the matrix visual with no succes, can someone give me syntax to create relevant calculation?

also' its very importent to show the target even if in there is no value in the sales table per target via key.

 

thank you.

1 ACCEPTED SOLUTION

@davidi4524 ,


Based on your sample data, the type column doesn't take effect on your expected result, you can add a type slicer to filter the table visual.

Besides, please check the last screenshot in my first reply. 

'At last, create a table visual as follows. Make sure you select “Show items with no data” for date field.'

Regards,

Community Support Team _ Lydia Zhang
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

9 REPLIES 9
v-yuezhe-msft
Employee
Employee

@davidi4524,

Firstly, in Query Editor of Power BI Desktop, click on target table, then choose “Merge Queries-> Merge Queries as New”.
1.PNG2.PNG


Secondly, expand the sale column from the NewColumn as shown in the following screenshot.
3.PNG4.PNG


Thirdly, create the measures below in the merged table.

target value = MAX(Merge1[target])
total sale = SUM(Merge1[NewColumn.sale])
delta = IF([total sale]=BLANK(),0,[total sale]-[target value])

At last, create a table visual as follows. Make sure you select “Show items with no data” for date field.
5.PNG


Regards,

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

hi,i forgot somthing, in the sales table i have a column named "type"

i need to show only data with the type 1 or 2 .

the type column didnt show on the merge table.

how can i filter only data with specific type? thanks.

@davidi4524,


In second step, you can expand the sale and type columns from the NewColumn, then you are able to filter the NewColumn.type column to only contain type 1 and type 2 data.

Regards,

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ok, and if i whant to show type 1 or 2 and its ok

but if i have a target with no sales its hide it when i applied this filter

what i neeed to do?

@davidi4524,

Could you please post the complete sample data of your sales table and post the expected result here?

Regards,

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

sales table:

datebranchsalekeytype of document
6/19/20174524106.19.201745241
6/19/20174524206.19.201745241
6/19/20174524306.19.201745241
6/19/20174524406.19.201745241
6/19/20174524506.19.201745242
6/20/20174524306.20.201745242
6/20/20174524406.20.201745242
6/20/20174524506.20.201745242
6/20/20174524606.20.201745242
6/20/20174524706.20.201745242
6/20/20174524806.20.201745242
6/20/20174524906.20.201745242
6/21/2017452416.21.201745243
6/21/2017452426.21.201745243
6/21/2017452436.21.201745243
6/21/2017452446.21.201745243
6/21/2017452456.21.201745243
6/21/2017452466.21.201745244
6/22/20174524206.22.201745244
6/22/20174524406.22.201745244
6/22/20174524606.22.201745244
6/22/20174524806.22.201745244
6/22/201745241006.22.201745245

 

target table:

datebranchtargetkey
6/19/201745241006.19.20174524
6/20/201745242006.20.20174524
6/21/201745243006.21.20174524
6/22/201745244006.22.20174524
07/01/2017452410007.1.20174524

 

 

need to show:

datebranchtargetkeytotal saledelta
6/19/201745241006.19.2017452415050
6/20/201745242006.20.20174524420220
6/21/201745243006.21.2017452421-279
6/22/201745244006.22.20174524300-100
07/01/2017452410007.1.20174524null0

 

note, that for the target in 7/1/2017 there is no sales data , but i steel need to show him.

 

thanks.

Hi,

Based on your sample data I have done it in a simple way.
I have created a relationship between target & sales (on field name "key") table than create 3 measures as below:

Measure1 (Target table):: Total_Target = sum(target)
Measure2 (Sales table):: Total_Sales = sum(sales)
Measure3 (Sales table):: Delta = Total_Target - Total_Sales

To filter the "type of document" I have put the slicer.

Hope this will address your concern.

All the best!

Regards,
Anupam

@davidi4524 ,


Based on your sample data, the type column doesn't take effect on your expected result, you can add a type slicer to filter the table visual.

Besides, please check the last screenshot in my first reply. 

'At last, create a table visual as follows. Make sure you select “Show items with no data” for date field.'

Regards,

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

hi, thank you very much for this detaild answer. im gonna try and let you know.

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.