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
Anonymous
Not applicable

Creating Margin for mulitple customers

Hi there,

I have created a logic for one of the customer “A” with the below formula and it is working fine.

PickUpCost-Cost =

    Var Cost = IF(Shipments[BilledOn]< DATE(2019,04,01), (1-0.228),

                      IF(Shipments[BilledOn]> DATE(2019,04,01) ||Shipments[BilledOn]< DATE(2020,04,01), (1-0.221), (0.219)))            

    Return

    IF(

LOOKUPVALUE('Financials'[Income],'Financials'[Invoice],Shipments[Invoice])-LOOKUPVALUE('Financials'[Cost],'Financials'[Invoice],Shipments[Invoice]) =        LOOKUPVALUE('Financials'[Profit],'Financials'[Invoice],Shipments[Invoice]),

   IF(OR(LOOKUPVALUE('Financials'[ss],'Financials'[Invoice],Shipments[Invoice])<=0.2,

            LOOKUPVALUE('Financials'[ss],'Financials'[Invoice],Shipments[Invoice])>=0.3),

    Cost*LOOKUPVALUE('Financials'[PC- Income],'Financials'[Invoice],Shipments[Invoice]),

            LOOKUPVALUE('Financials'[PC- cost],  'Financials'[Invoice],Shipments[Invoice])),

    Cost*LOOKUPVALUE('Financials'[PC- Income],'Financials'[Invoice],Shipments[Invoice]))

 

Now I am trying to create same formula for multiple customers with different Margins but it is not working

Index

Start Date

End Date

       A

       B

      C

       D

1

1/1/2018

3/31/2019

0.228

0.209

0.228

0.228

2

4/1/2019

3/31/2020

0.221

0.209

0.221

0.221

3

4/1/2020

3/31/2021

0.219

0.209

0.219

0.219

 

Could anyone please help how to create formula for all customers, its very urgent and very important.

I have tried using

(CALCULATE (FIRSTNONBLANK('Financials'[Income],1),FILTER(ALL('Financials'), 'Scope'[Invoice] = 'Shipments'[Invoice]))

instead of LOOKUP Function but still it is not working

Please let me know if any other details are required

Thanks in advance.

10 REPLIES 10
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Could you please share sample data or sample .pbix?

 

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

Anonymous
Not applicable

Thanks for the response.

 

Please let me know how to share data so that i can share sample data. 

 

Hi @Anonymous ,

 

Screenshot,Copy and paste sample data in a table,Cloud service like OneDrive for business.

 

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

Anonymous
Not applicable

Please find sample data below:

 

InvoicePC - IncomePC - CostPC - ProfitBilled OnssCustomer 
20010647073.7057.5616.144/3/202021.9%A
20010624057.6245.0012.624/3/202021.9%A
200106210160.05125.0035.054/3/202021.9%A
20010614857.6245.0012.624/3/202021.9%A
200105861420.28328.2492.044/3/202021.9%A
1900936921,753.531,613.18140.353/16/202020.3%B
190095887802.10737.9064.203/16/202020.3%B
190093348802.10737.9064.203/16/202020.3%B
200105535839.83772.6167.223/27/202020.3%B
200105561398.89366.9631.933/27/202020.3%B
200104361102.7280.0022.723/20/202022.1%C
20010598257.7845.0012.784/1/202022.1%C
200105983192.60150.0042.604/1/202022.1%C
200105984205.44160.0045.444/1/202022.1%C
2001063966,123.054,880.071,242.984/10/202021.9%D
2001060603,756.592,994.00762.594/10/202021.9%D
2001060643,658.852,916.10742.754/10/202021.9%D
2001058544,381.793,492.29889.504/10/202021.9%D

 

 

Margin Table:

IndexStart DateEnd DateABCD
11/1/20183/31/20190.2280.2030.2280.228
24/1/20193/31/20200.2210.2030.2210.221
34/1/20203/31/20210.2190.2030.2190.219

Expecting Output is PC Cost with below margin according to date and customer.




Please find below table for the refernece which i have worked earlier and got the Expexted PC Cost

 

InvoicePickup Costs - IncomePickup Costs - CostPickup Costs - ProfitBilled OnssCustomer Expected PC Cost
190067733482.51375.79106.729/20/20190.22A375.8753
190067742188.36146.7041.665/17/20190.22A146.7324
19006347287.5968.2219.374/19/20190.22A68.23261
19007320857.7845.0012.788/30/20190.22A45.01062
19007397996.3075.0021.308/30/20190.22A75.0177
19007605557.7845.0012.789/27/20190.22A45.01062
1900762961177.94917.40260.549/20/20190.22A917.6153
190077854428.88334.1094.788/8/20190.22A334.0975
19008042557.7845.0012.788/30/20190.22A45.01062
190083738403.55314.2989.2610/10/20190.22A314.3655
190083671204.40159.1945.2110/10/20190.22A159.2276
190083933151.29117.8333.4610/10/20190.22A117.8549
190084277545.70425.00120.708/30/20190.22A425.1003
190065866381.62297.2184.419/6/20190.22A297.282
190065712143.86112.0431.829/6/20190.22A112.0669
190085442124.7997.1927.6010/4/20190.22A97.21141
19008328196.3075.0021.3010/10/20190.22A75.0177
190086181256.80200.0056.8010/11/20190.22A200.0472
190081184288.90225.0063.9010/28/20190.22A225.0531
190086651644.62502.04142.5812/20/20190.22A502.159
19008780557.7845.0012.7810/4/20190.22A45.01062
190088671551.48429.50121.9810/4/20190.22A429.6029
190088637179.79140.0239.7710/4/20190.22A140.0564
190089021417.30325.0092.3011/1/20190.22A325.0767
190094008288.90225.0063.9012/13/20190.22A225.0531
190093973465.04362.18102.8612/13/20190.22A362.2662
190095128108.2784.3223.9512/13/20190.22A84.34233
19009539657.7845.0012.7812/13/20190.22A45.01062
190095382703.12547.60155.5212/13/20190.22A547.7305

Margin Table:

IndexStart DateEnd DateA
11/1/20183/31/20190.228
24/1/20193/31/20200.221
34/1/20203/31/20210.219

 

Im looking for "EXPECTED PC COST" for all customers.

 

Anonymous
Not applicable

Hi there,

I have created a logic for one of the customer “A” with the below formula and it is working fine.

PickUpCost-Cost =

    Var Cost = IF(Shipments[BilledOn]< DATE(2019,04,01), (1-0.228),

                      IF(Shipments[BilledOn]> DATE(2019,04,01) ||Shipments[BilledOn]< DATE(2020,04,01), (1-0.221), (0.219)))            

    Return

    IF(

LOOKUPVALUE('Financials'[Income],'Financials'[Invoice],Shipments[Invoice])-LOOKUPVALUE('Financials'[Cost],'Financials'[Invoice],Shipments[Invoice]) =        LOOKUPVALUE('Financials'[Profit],'Financials'[Invoice],Shipments[Invoice]),

   IF(OR(LOOKUPVALUE('Financials'[ss],'Financials'[Invoice],Shipments[Invoice])<=0.2,

            LOOKUPVALUE('Financials'[ss],'Financials'[Invoice],Shipments[Invoice])>=0.3),

    Cost*LOOKUPVALUE('Financials'[PC- Income],'Financials'[Invoice],Shipments[Invoice]),

            LOOKUPVALUE('Financials'[PC- cost],  'Financials'[Invoice],Shipments[Invoice])),

    Cost*LOOKUPVALUE('Financials'[PC- Income],'Financials'[Invoice],Shipments[Invoice]))

 

Now I am trying to create same formula for multiple customers with different Margins but it is not working

 

Index

Start Date

End Date

       A

       B

      C

       D

1

1/1/2018

3/31/2019

0.228

0.209

0.228

0.228

2

4/1/2019

3/31/2020

0.221

0.209

0.221

0.221

3

4/1/2020

3/31/2021

0.219

0.209

0.219

0.219

 

Could anyone please help how to create formula for all customers, its very urgent and very important.

 

I have tried using

(CALCULATE (FIRSTNONBLANK('Financials'[Income],1),FILTER(ALL('Financials'), 'Scope'[Invoice] = 'Shipments'[Invoice]))

instead of LOOKUP Function but still it is not working

 

Please let me know if any other details are required

 

Thanks in advance.

Hi   @Anonymous ,

 

What is the value you are trying to return on the lookupvalue?

 

Believe that your measurements is complicated and may be made in a different way however there is not very much information about your model so the reading of your measure is complicated with the given data.

 

Also believe that if you want to have this in a dinamice way you need to unpivot the table you present and as a consequence change the formula you presented.

 

Can you share a sample file and expected values?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi Felix,
Thanks for the reply.
I am unable to attach file here. Could you please let know how to share sample data or pbix file, so that i can explain you clearly what iam looking for.

I have created logic for PC Cost with margin for one customer and it is working fine.

 

Now iam looking for PC Cost for all customers combined.

Hi @Anonymous ,

 

You could upload your sample .pbix to a cloud storage service (like OneDrive for business) and paste the link to that storage location in the post.

 

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

bheepatel
Resolver IV
Resolver IV

Hi @Anonymous 

 

One possible solution is to pivot your table so that you have your table in the same format as Table B below. You can use the pivot options available to you in Power Query.

3.JPG

 

 

Once you have that, you can create the measure similar to the one below, where you can change the Customer and BilledOnDate variables to suit your needs. Below screenshots show you examples for two different customers and billing dates.

1.JPG

 

2.JPG

 

Hope this helps!

Anonymous
Not applicable

Thanks for the reply.

I have created “GetValue” measure and I got Values for A,B,C,D

Below is the formula for Customer ‘A’ and I got the result.

PC-Cost =
   Var Cost = IF( Shipments[BilledOn]< DATE(2019,04,01), (1-0.228), IF(Shipments[BilledOn]> DATE(2019,04,01)       

                       ||Shipments[BilledOn]< DATE(2020,04,01), (1-0.221), (0.219)) )
   Return
IF
( LOOKUPVALUE('Financials'[Income],'Financials'[Invoice],Shipments[Invoice])-LOOKUPVALUE('Financials'[Cost],'Financials'[Invoice],Shipments[Invoice]) = LOOKUPVALUE('Financials'[Profit],'Financials'[Invoice],Shipments[Invoice]), IF(OR(LOOKUPVALUE('Financials'[ss],'Financials'[Invoice],Shipments[Invoice])<=0.2, LOOKUPVALUE('Financials'[ss],'Financials'[Invoice],Shipments[Invoice])>=0.3),
Cost*LOOKUPVALUE('Financials'[PC- Income],'Financials'[Invoice],Shipments[Invoice]),
LOOKUPVALUE('Financials'[PC- cost], 'Financials'[Invoice],Shipments[Invoice])),
Cost*LOOKUPVALUE('Financials'[PC- Income],'Financials'[Invoice],Shipments[Invoice]))

 

Now I have to create for all customers (ABCD)
Could you please let me know how can I use ‘’GetValue” in the above formula

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.