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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
saurabhg
New Member

Calculation Context in Power BI desktop while creating new Measure

Hi Guru's,

 

I am starting my dev journey with Power BI and need some help on calcualtion context for my Power BI Desktop report.

 

My Question is:

"Numeric Value in one of the attribute from data table is repeating every row but that is static value for combination of few other columns, how can we ignore row level calculation and still use that numeric value for other grouped calculation in power BI"

 

Clarifying with an Example data set:

 

Column A, Column B and Column C are (Dimesion) in my data

I have Column D and Column E as 2 measures in the same data set

I am bringing Column F, Column G and Column H from another table by joining on the basis of Column A/B/C which are between both the tables.

 

Now if I pull out A,B,C,D,E in the report all good D and E are summarize and grouped by A/B/C values all OK

but if I want to use numeric value (F/G/H) from other table the calculation goes each row but what I want is F/G/H should be same value while grouping on the basis of A/B/C

 

A                        B            C                        D      E          F   G   H

Prodcut1            City1      Postal Code1     10     12        1   1   1

Prodcut1            City1      Postal Code1     22     13        1   1   1

Prodcut1            City1      Postal Code1     34     45        1   1   1

Prodcut2            City2      Postal Code2     07     30        2   2   2

Prodcut2            City2      Postal Code2     15     29        2   2   2

Prodcut2            City2      Postal Code2     14     31        2   2   2   

 

If I summarize:

 

A                        B            C                        D      E 

Prodcut1            City1      Postal Code1     66     70

Prodcut2            City2      Postal Code2     36     90

 

But if I want to create another calculated column I want to use summarize value of D and E but single value of F/G/H as 1 for product 1 and 2 for product 2 in my calculation, but what is happening is the derived column is calcualting row level and the formula works at each row.

so lets say if I want to create a calcualted column by multiplying D with F then it should be 66*1 for Product 1 and 36*2 for Product 2 in my calculation.

I understand this is calcualtion context and use to do such things in Business Obejcts by for all and for each function but not able to perform the same in Power BI Desktop

 

any pointer on this is helpful

Thanks!

 

9 REPLIES 9
saurabhg
New Member

Hi

I have attached both tables structure with sample data above.

Tables are joined on the basis of 

PRODUCT_ID ,SUB_PRODUCT_ID,  CATEGORY
and SALES_DATE in Table 1 falling between EFF_FROM_DT and EFF_TIL_DT in table 2 , so only matching row from Table 2 with date range as per sales date is picked. I have comeup until this point by joining both tables on key columns and filtering for SALES_DATE between EFF_FROM_DT and EFF_TIL_DT in table 2. So maximum number of rows I can have is number of rows under Table 1 (left outer join)

 

Now what I want to achieve is for the combination of PRODUCT_ID ,SUB_PRODUCT_ID,  CATEGORY and SALES_DATE get sum of TOTAL_PRODUCT_COUNT and TOTAL_SALES, which is ok and already done now a calculated column need to be created which tells me below:

 

DERIVED_COLUMN- which in case of if ABSOLUTE_OR_PERCENTAGE is ABSOLUTE THEN EXPECTED_SALES ELSE IF ABSOLUTE_OR_PERCENTAGE is PERCENTAGE THEN IF (EXPECTED_SALES*TOTAL_PRODUCT_COUNT) < MIN_SALES THEN MIN_SALES ELSEIF (EXPECTED_SALES*TOTAL_PRODUCT_COUNT) > MAX_SALES THEN MAX_SALES ELSE (EXPECTED_SALES*TOTAL_PRODUCT_COUNT)

Table 2

PRODUCT_IDSUB_PRODUCT_IDCATEGORYEXPECTED_SALESABSOLUTE_OR_PERCENTAGEMIN_SALESMAX_SALESEFF_FROM_DTEFF_TIL_DT
PROD_1SUB_PROD_1CAT_15%PERCENTAGE10501-Jan-2331-Jan-23
PROD_1SUB_PROD_1CAT_25%PERCENTAGE10501-Jan-2331-Jan-23
PROD_1SUB_PROD_1CAT_15%PERCENTAGE5201-Feb-2331-Dec-99
PROD_1SUB_PROD_1CAT_25%PERCENTAGE5201-Feb-2331-Dec-99
PROD_1SUB_PROD_2CAT_320ABSOLUTE  1-Jan-2331-Jan-23
PROD_1SUB_PROD_2CAT_410ABSOLUTE  1-Jan-2331-Jan-23
PROD_1SUB_PROD_2CAT_310ABSOLUTE  1-Feb-2331-Dec-99
PROD_1SUB_PROD_2CAT_45ABSOLUTE  1-Feb-2331-Dec-99
PROD_2SUB_PROD_3CAT_510%PERCENTAGE10501-Feb-2331-Dec-99
PROD_2SUB_PROD_3CAT_55%PERCENTAGE5201-Feb-2331-Dec-99
PROD_2SUB_PROD_4CAT_65ABSOLUTE  1-Jan-2331-Jan-23
PROD_2SUB_PROD_4CAT_710ABSOLUTE  1-Jan-2331-Jan-23
PROD_2SUB_PROD_4CAT_610ABSOLUTE  1-Feb-2331-Dec-99
PROD_2SUB_PROD_4CAT_710ABSOLUTE  1-Feb-2331-Dec-99

PRODUCT_IDSUB_PRODUCT_IDCATEGORYSALES_DATESALES_PERSON_IDTOTAL_PRODUCT_COUNTTOTAL_SALES
PROD_1SUB_PROD_1CAT_131-Jan-23101503
PROD_1SUB_PROD_1CAT_128-Feb-231021007
PROD_1SUB_PROD_1CAT_131-Jan-23103236
PROD_1SUB_PROD_1CAT_128-Feb-23104245
PROD_1SUB_PROD_1CAT_131-Jan-23105522
PROD_1SUB_PROD_1CAT_128-Feb-23106434
PROD_1SUB_PROD_1CAT_131-Jan-23107633
PROD_1SUB_PROD_1CAT_128-Feb-23108193
PROD_1SUB_PROD_1CAT_131-Jan-23109207
PROD_1SUB_PROD_1CAT_128-Feb-23101456
PROD_1SUB_PROD_1CAT_231-Jan-23102295
PROD_1SUB_PROD_1CAT_228-Feb-23103302
PROD_1SUB_PROD_1CAT_231-Jan-23104314
PROD_1SUB_PROD_1CAT_228-Feb-23105423
PROD_1SUB_PROD_1CAT_231-Jan-23106573
PROD_1SUB_PROD_1CAT_231-Jan-23107857
PROD_1SUB_PROD_1CAT_228-Feb-23108626
PROD_1SUB_PROD_1CAT_231-Jan-23109345
PROD_1SUB_PROD_1CAT_228-Feb-23101562
PROD_1SUB_PROD_1CAT_231-Jan-23102124
PROD_1SUB_PROD_2CAT_331-Jan-23103103
PROD_1SUB_PROD_2CAT_328-Feb-23104203
PROD_1SUB_PROD_2CAT_331-Jan-23105307
PROD_1SUB_PROD_2CAT_328-Feb-23106536
PROD_1SUB_PROD_2CAT_331-Jan-23107635
PROD_1SUB_PROD_2CAT_331-Jan-23108232
PROD_1SUB_PROD_2CAT_328-Feb-23109244
PROD_1SUB_PROD_2CAT_331-Jan-23101523
PROD_1SUB_PROD_2CAT_328-Feb-23102433
PROD_1SUB_PROD_2CAT_331-Jan-23103637
PROD_1SUB_PROD_2CAT_328-Feb-23104196
PROD_1SUB_PROD_2CAT_431-Jan-23105205
PROD_1SUB_PROD_2CAT_428-Feb-23106452
PROD_1SUB_PROD_2CAT_431-Jan-23107294
PROD_1SUB_PROD_2CAT_428-Feb-23108303
PROD_1SUB_PROD_2CAT_431-Jan-23109313
PROD_1SUB_PROD_2CAT_428-Feb-23101427
PROD_1SUB_PROD_2CAT_431-Jan-23102576
PROD_1SUB_PROD_2CAT_428-Feb-23103855
PROD_1SUB_PROD_2CAT_431-Jan-23104622
PROD_1SUB_PROD_2CAT_428-Feb-23105344
PROD_1SUB_PROD_2CAT_431-Jan-23106563
saurabhg
New Member

Table 2:

PRODUCT_IDSUB_PRODUCT_IDCATEGORYEXPECTED_SALESABSOLUTE_OR_PERCENTAGEMIN_SALESMAX_SALESEFF_FROM_DTEFF_TIL_DT
PROD_1SUB_PROD_1CAT_15%PERCENTAGE10501-Jan-2331-Jan-23
PROD_1SUB_PROD_1CAT_25%PERCENTAGE10501-Jan-2331-Jan-23
PROD_1SUB_PROD_1CAT_15%PERCENTAGE5201-Feb-2331-Dec-99
PROD_1SUB_PROD_1CAT_25%PERCENTAGE5201-Feb-2331-Dec-99
PROD_1SUB_PROD_2CAT_320ABSOLUTE  1-Jan-2331-Jan-23
PROD_1SUB_PROD_2CAT_410ABSOLUTE  1-Jan-2331-Jan-23
PROD_1SUB_PROD_2CAT_310ABSOLUTE  1-Feb-2331-Dec-99
PROD_1SUB_PROD_2CAT_45ABSOLUTE  1-Feb-2331-Dec-99
PROD_2SUB_PROD_3CAT_510%PERCENTAGE10501-Feb-2331-Dec-99
PROD_2SUB_PROD_3CAT_55%PERCENTAGE5201-Feb-2331-Dec-99
PROD_2SUB_PROD_4CAT_65ABSOLUTE  1-Jan-2331-Jan-23
PROD_2SUB_PROD_4CAT_710ABSOLUTE  1-Jan-2331-Jan-23
PROD_2SUB_PROD_4CAT_610ABSOLUTE  1-Feb-2331-Dec-99
PROD_2SUB_PROD_4CAT_710ABSOLUTE  1-Feb-2331-Dec-99
saurabhg
New Member

Table 1 : 

PRODUCT_IDSUB_PRODUCT_IDCATEGORYSALES_DATESALES_PERSON_IDTOTAL_PRODUCT_COUNTTOTAL_SALES
PROD_1SUB_PROD_1CAT_131-Jan-23101503
PROD_1SUB_PROD_1CAT_128-Feb-231021007
PROD_1SUB_PROD_1CAT_131-Jan-23103236
PROD_1SUB_PROD_1CAT_128-Feb-23104245
PROD_1SUB_PROD_1CAT_131-Jan-23105522
PROD_1SUB_PROD_1CAT_128-Feb-23106434
PROD_1SUB_PROD_1CAT_131-Jan-23107633
PROD_1SUB_PROD_1CAT_128-Feb-23108193
PROD_1SUB_PROD_1CAT_131-Jan-23109207
PROD_1SUB_PROD_1CAT_128-Feb-23101456
PROD_1SUB_PROD_1CAT_231-Jan-23102295
PROD_1SUB_PROD_1CAT_228-Feb-23103302
PROD_1SUB_PROD_1CAT_231-Jan-23104314
PROD_1SUB_PROD_1CAT_228-Feb-23105423
PROD_1SUB_PROD_1CAT_231-Jan-23106573
PROD_1SUB_PROD_1CAT_231-Jan-23107857
PROD_1SUB_PROD_1CAT_228-Feb-23108626
PROD_1SUB_PROD_1CAT_231-Jan-23109345
PROD_1SUB_PROD_1CAT_228-Feb-23101562
PROD_1SUB_PROD_1CAT_231-Jan-23102124
PROD_1SUB_PROD_2CAT_331-Jan-23103103
PROD_1SUB_PROD_2CAT_328-Feb-23104203
PROD_1SUB_PROD_2CAT_331-Jan-23105307
PROD_1SUB_PROD_2CAT_328-Feb-23106536
PROD_1SUB_PROD_2CAT_331-Jan-23107635
PROD_1SUB_PROD_2CAT_331-Jan-23108232
PROD_1SUB_PROD_2CAT_328-Feb-23109244
PROD_1SUB_PROD_2CAT_331-Jan-23101523
PROD_1SUB_PROD_2CAT_328-Feb-23102433
PROD_1SUB_PROD_2CAT_331-Jan-23103637
PROD_1SUB_PROD_2CAT_328-Feb-23104196
PROD_1SUB_PROD_2CAT_431-Jan-23105205
PROD_1SUB_PROD_2CAT_428-Feb-23106452
PROD_1SUB_PROD_2CAT_431-Jan-23107294
PROD_1SUB_PROD_2CAT_428-Feb-23108303
PROD_1SUB_PROD_2CAT_431-Jan-23109313
PROD_1SUB_PROD_2CAT_428-Feb-23101427
PROD_1SUB_PROD_2CAT_431-Jan-23102576
PROD_1SUB_PROD_2CAT_428-Feb-23103855
PROD_1SUB_PROD_2CAT_431-Jan-23104622
PROD_1SUB_PROD_2CAT_428-Feb-23105344
PROD_1SUB_PROD_2CAT_431-Jan-23106563
Sahir_Maharaj
Super User
Super User

Hello @saurabhg,

 

Can you please try this:

 

1. Summarized Value of D

Total D = SUM(YourTable[D])

2. Unique Value of F

Unique F = MIN(YourTable[F])

3. Combined Measure

D times Unique F = [Total D] * [Unique F]

When you use the D times Unique F measure in a visual along with A, B, C, it should display the product of the sum of D and the unique value of F for each group defined by A, B, C. Should you require any further assistance, please do not hesitate to reach out to me.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi Sahir,

Thanks for the reply but still the calculation doesnt works as 

Total D = SUM(YourTable[D])

gives me total sum of values under column D which is - 102, even after using it along with other columns A,B and C 

Hi @saurabhg ,

Could you please provide some raw data in your table1(which include the field A, B and C) and table2(which include F,G and H)  (exclude sensitive data) with Text format, the formula of E&F and your expected result? By the way, is there any relationship between table1 and table2? If yes, please provide the relationship info(cardinality, direction etc.). It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

Hi All,

 

any help on this topic please?

Let  me know if the issue or required calculation is not clear with my post?

 

My ask is to perform any calculation not at row level (at each rows of raw data) but to sum few values on the basis of grouping columns and then for the same group get unique value of another measure which is used for creating some calculated variables.

 

 

Regards,

Saurabh Gupta

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.