Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello. My table multiple columns but only these three interest for my question:
Order_Number || Picking_Date || Product_State
If a customer orders more than one product, the order_number appears repeated like these:
Order_Number || Picking_Date || Product_State
700200 XX/XX/XXXX Picked
700200 Canceled
I don't have the picking date from some orders so I want to, for the entries that Picking_date is blank and the product_state is "canceled", assume the first picking date for the same order_number if the same order has more than one product entry. For that I have the following expression:
=IF(Query_[Picking_date]=BLANK() && Query_[Product_state]="Canceled";IF(HASONEVALUE(Query_[Order_Number]);FIRSTDATE(Query_[Picking_date]);"without entries");Query_[Picking_date]).
But returns this error: Expressions that yield variant data-type cannot be used to define calculated columns.
My picking_date has date format, my order_number has whole number format and Product state has text format.
Thank you.
Solved! Go to Solution.
@Anonymous
You cannot mix two data types in a single column, you have got dates and text.
Try the following code to add a new column
M =
VAR _ORDER = Query[Order_Number]
RETURN
IF(
ISBLANK(Query[Picking_Date]) && Query[Product_State]="Cancelled",
var _date = CALCULATE(MAX(Query[Picking_Date]), Query[Order_Number] = _ORDER, ALL(Query))
var _dateformated =_date return
IF( ISBLANK(_date), BLANK() , _dateformated),
Query[Picking_Date]
)
________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon on the right if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@Anonymous
You cannot mix two data types in a single column, you have got dates and text.
Try the following code to add a new column
M =
VAR _ORDER = Query[Order_Number]
RETURN
IF(
ISBLANK(Query[Picking_Date]) && Query[Product_State]="Cancelled",
var _date = CALCULATE(MAX(Query[Picking_Date]), Query[Order_Number] = _ORDER, ALL(Query))
var _dateformated =_date return
IF( ISBLANK(_date), BLANK() , _dateformated),
Query[Picking_Date]
)
________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon on the right if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@Anonymous Try something like this:
Column =
VAR CurrentOrderNumber = jmsm[Order_Number]
VAR CurrentPickingDate = jmsm[Picking_Date]
VAR CurrentProductState = jmsm[Product_State]
VAR MaxDate =
MAXX (
FILTER (
jmsm,
jmsm[Order_Number] = CurrentOrderNumber
&& jmsm[Product_State] <> "Canceled"
&& NOT ISBLANK ( jmsm[Picking_Date] )
),
jmsm[Picking_Date]
)
VAR Result =
IF (
ISBLANK ( CurrentPickingDate )
&& CurrentProductState = "Canceled",
MaxDate
)
RETURN
Result
User | Count |
---|---|
25 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
27 | |
13 | |
13 | |
11 | |
6 |