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
ArashZ
Helper I
Helper I

calculated column

Hi,

 

I have a table like the below:

There are some companies on the table and each one sells different products. As can be seen, in the table, if the product code is glasses or shipping or additional item, the plan frequency column is monthly; otherwise is yearly. I want to create a new plan frequency modified column in a way that if a car or pen or pencil exists for that company, all the plan frequencies for that company change to yearly. The new desired common is also shown.

 

Company NamePlan frequencyProductcode
AMonthlyglasses
AMonthlyshipping
AYearlycar
AYearlypen
BMonthlyglasses
BYearlypen
BYearlypencil
BYearlybottle
CMonthlyglasses
CMonthlyshipping
CYearlycar
CYearlypen
CMonthlyadditional item

 

ArashZ_0-1664262517606.png

 

7 REPLIES 7
wdx223_Daniel
Super User
Super User

CalculatedColumn=VAR _c=Data[Company Name] RETURN IF(COUNTROWS(FILTER(Data,Data[Company Name]=_c&&Data[Productcode] IN {"car","pen","pencil"})),"Yearly",Data[Plan frequency])

@wdx223_Daniel 

 

Thank you, but the solution doesn't work. The table still shows some monthly values.

Hi, @ArashZ 

If @wdx223_Daniel 's formula doesn't work, can you show relevant screenshots to further investigate what's causing the error?

Also, check if the bias in the results is caused by errors in the data itself.

Best Regards,
Community Support Team _ Eason

AnthonyJoseph
Resolver III
Resolver III

Hi @ArashZ 

I think this is what you are looking for...

Plan Frequency Modified = 
var _isinlist = CALCULATE(COUNT('Table'[Productcode]),CONTAINSROW({"car","pen","pencil"},'Table'[Productcode]),FILTER(ALLEXCEPT('Table','Table'[Company Name]),'Table'[Company Name] = EARLIER('Table'[Company Name])))
return
if(_isinlist >=1,"Yearly", "Monthly")

 

AnthonyJoseph_0-1664264836681.png

Hope this helps!

 

Thanks, 

AnthonyJoseph

@AnthonyJoseph 

 

Thanks, but I received this error.

A single value for the column company name in the table cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation to get a single result.

Hi @ArashZ 
Would you be able to share the DAX that you tried so that I can see if there are any syntatical errors.
Thanks,
AnthonyJoseph

Hi @ArashZ 

 

Please can you provide data anonymising/removing the sensitive information.

 

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