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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
LucaixBolha
Resolver I
Resolver I

Text calculated column filtered by value condition (power bi)

Hey guys can someone help me out with this please:

I have several Stock IDs from enterprises, being that an enterprise could have just a single value for its Stock ID, as well as various, having always a base of 4 initial letters (for example the enterprise with the Stock ID "AHEB" has AHEB3, AHEB5 and AHEB6).

My goal is to create a calculated column that already filters these IDs by negotiability (only the most negotiated ID for each enterprise should remain in this column). I'm sending a pbix example of the problem: https://file.io/Rg3izoPcapgW

Creating a new column with just the 4 initial letters as I did in the following example would be perfect for my other purposes if it showed also the rest of the ID (numbers/letters)

1 ACCEPTED SOLUTION

Ahh I got it @grantsamborn! But the solution came from another way: I created these three formulas, and filtered my slicer with a Top N visual level filter, adding the variable "FILTERSTOCK" to it, so that it would filter only the Stock Codes that correspond to "TRUE". Here are the formulas, followed by the link with the file:

1) Last negotiated value column =

VAR RESULT =
CALCULATE(
LASTNONBLANKVALUE('Database'[Date],max('Database'[negotiated value]))
)
RETURN RESULT

2) MaxValuePerStock =
VAR CurrentStock = max('Stock Codes'[Stock without numbers/letters])
VAR RESULT =
CALCULATE(
[last negotiated value column],
FILTER(ALL('Stock Codes'), 'Stock Codes'[Stock without numbers/letters] = CurrentStock)
)
RETURN RESULT

3) FILTERSTOCK = if([last negotiated value column]=[MaxValuePerStock],
TRUE(),
BLANK())

File: https://we.tl/t-ADYymPKNDs

Thank you very much!!! 🙏😊

View solution in original post

14 REPLIES 14
grantsamborn
Solution Sage
Solution Sage

Take a look at this and let me know if it helps.

 

https://1drv.ms/u/s!AnF6rI36HAVkhPEtenBRgHzse3BGpA?e=hzCLio

 

Edited to add:  After rereading your post, I realized you wanted a calculated column instead of measure(s).

 

Hmm almost, thank you very much for your time! Maybe reformulating my goal would help to be clearer: I would like to have a slicer containing only one code per enterprise (more specifically the codes of the Stocks that are the most negotiated by value, like AHEB6, ALPA4, ALUP11, etc, on the most recent available data). 

This time I created a calculated table by using the measures I previously wrote, and then created a many-to-one relationship between 'Database'[Stock] and 'zSummary'[Date].

 

https://1drv.ms/u/s!AnF6rI36HAVkhPEuzwSQhZibpIEm-A?e=RHtne6

 

Let me know if this helps.

Same except, I removed the measures making it cleaner.

 

https://1drv.ms/u/s!AnF6rI36HAVkhPEvjDvTOr_cQSaooQ?e=UG6TMu

 

Ahh I got it @grantsamborn! But the solution came from another way: I created these three formulas, and filtered my slicer with a Top N visual level filter, adding the variable "FILTERSTOCK" to it, so that it would filter only the Stock Codes that correspond to "TRUE". Here are the formulas, followed by the link with the file:

1) Last negotiated value column =

VAR RESULT =
CALCULATE(
LASTNONBLANKVALUE('Database'[Date],max('Database'[negotiated value]))
)
RETURN RESULT

2) MaxValuePerStock =
VAR CurrentStock = max('Stock Codes'[Stock without numbers/letters])
VAR RESULT =
CALCULATE(
[last negotiated value column],
FILTER(ALL('Stock Codes'), 'Stock Codes'[Stock without numbers/letters] = CurrentStock)
)
RETURN RESULT

3) FILTERSTOCK = if([last negotiated value column]=[MaxValuePerStock],
TRUE(),
BLANK())

File: https://we.tl/t-ADYymPKNDs

Thank you very much!!! 🙏😊

Hi

I'm not sure how much I helped but glad you got it figured out.

Ohh almost perfect @grantsamborn, thank you very much!! For a great part of them your code recognized the right Stock Code to be displayed, but for some of them not yet. For example ALUP should be ALUP11 instead of ALUP4 , BDLL3 instead of 4, and other cases like BRAP99, that is appearing in the slicer, but not in the table (didn't quite understand what happenned with this one 🤔).  

In your initial description of the problem, you said "only the most negotiated ID for each enterprise should remain in this column."  Can you explain this?

 

When 2 (or more) Stocks for a single Enterprise appear on the latest (non-blank) date, I'm not sure which to use.

 

Did you mean to use the row count per Stock as the tie-breaker?

 

grantsamborn
Solution Sage
Solution Sage

When trying to download your pbix, I'm told "The transfer you requested has been deleted."

whoops, my bad! here it is @grantsamborn : https://file.io/SwSi19PQGZgv

Still the same problem.

strange! Try this one out please @grantsamborn : https://we.tl/t-8q01qvOkFj

OK - that link worked.

LucaixBolha
Resolver I
Resolver I

LucaixBolha_0-1657569182641.png

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors