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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
haefnja
Frequent Visitor

New grouping column

I am looking to add a grouping column that looks at the values in a few different columns to determine the value that should be entered.  My data is from a production table that records the good product and scrap that is created on a shift, as well as the various reasons for the scrap.  The entries on the same shift are grouped by the ReferenceID value, the good product code or scrap code shows in the ProductDescription, and a sorting characteristic in the ProductType that helps show whether it is a good product (G) or scrap (S).  What I want to do is add a column where every entry on that ReferenceID gets the ProductDescription of the good product (ProductType = G) so that I can sort and see which scrap reasons we get when running certain products.  Example of the data is below...can anyone help me out on this?

 

ReferenceIDProductDescriptionProductTypeWhat we are running (column I am trying to make)
12323Q 04S5050667
12323Q 01S5050667
12323QD 30S5050667
12323Q 01S5050667
123235050667G5050667
12430QD 30S5050667
124305050667G5050667
125155081245G5081245
12515QD 31S5081245
12515QD 36S5081245
    
12573QD 46S5081245
125735081245G5081245
    
125815081245G5081245
12581QD 32S5081245
12695QD 30S5081245
126955081245G5081245
128365081245G5081245
12836QD 30S5081245
12836Q 12S5081245
12836Q 09S5081245

 

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=CALCULATE(MAX(Data[ProductDescription]),FILTER(Data,Data[ReferenceID]=EARLIER(Data[ReferenceID])&&Data[ProductType]="G"))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Hey @haefnja ,

 

DirectQuery is a big difference.

The problem is not CALCULATE, the CALCULATE function works with DirectQuery. The problems are usually the limits for calculated tables and calculated columns.

 

In your case add the column in your data source, from my point of view that's the best place to do that for your case.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

6 REPLIES 6
haefnja
Frequent Visitor

So update to close this out, I ended up having to make a few new tables.  first was a new calculated filtered table that just brings in the referenceID and product description for only product type of "G".  Then, I had to make another table that brings in the data from the main table, but import instead of direct query.  once it imports, I can use the lookup value for a new column that looks for the referenceID and returns the good product code.  probably a very round-about way to do it, but it's working so I am happy.  Thanks to @selimovd and @Ashish_Mathur for trying to help!

haefnja
Frequent Visitor

Thanks for the help @Ashish_Mathur and @selimovd.  It looks like it should work, but I ran into an issue I was not expecting.  I am using this in DirectQuery mode, since it is a live system that is constantly getting new data entered from the production floor.  Since it is DirectQuery, I cannot use the CALCULATE function...any suggestions?

Hey @haefnja ,

 

DirectQuery is a big difference.

The problem is not CALCULATE, the CALCULATE function works with DirectQuery. The problems are usually the limits for calculated tables and calculated columns.

 

In your case add the column in your data source, from my point of view that's the best place to do that for your case.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

I don't have direct access to the database that is acting as the data source, so if I can't get it into my data source, is there another way I can go about this? Is there a different way to basically say in a new column "For all the same ReferenceID values, take the ProductDescription when ProductType = G"? I think you understand well enough what I am trying to do, I just don't understand why I can't get it to work properly.

Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=CALCULATE(MAX(Data[ProductDescription]),FILTER(Data,Data[ReferenceID]=EARLIER(Data[ReferenceID])&&Data[ProductType]="G"))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
selimovd
Super User
Super User

Hey @haefnja ,

 

the following calculated column should give you the desired result:

Description G =
VAR vRowReferenceID = myTable[ReferenceID]
VAR vDescr =
    CALCULATE(
        MAX( myTable[ProductDescription] ),
        myTable[ProductType] = "G",
        myTable[ReferenceID] = vRowReferenceID,
        myTable
    )
RETURN
    vDescr

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Helpful resources

Announcements
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.