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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
CalebR
Resolver I
Resolver I

Combining two measures and adding an IF

Hello, I am still new to power BI and how its formatting works so Im not sure how to accomplish this. I have two measures:

SinglePOs = 
  VAR PO = MAX(PO_PurchaseOrderDetail[PurchaseOrderNo])
  VAR PREVPO = CALCULATE(MAX(PO_PurchaseOrderDetail[PurchaseOrderNo]), PO_PurchaseOrderDetail[PurchaseOrderNo] < PO)
  VAR Rec = MAXX(FILTER(PO_PurchaseOrderDetail,[PurchaseOrderNo] = PO),[Received])
  VAR PREVREC = MAXX(FILTER(PO_PurchaseOrderDetail,[PurchaseOrderNo] = PREVPO),[Received])
  VAR Qty = MAXX(FILTER(PO_PurchaseOrderDetail,[PurchaseOrderNo] = PO),[QuantityOrdered])
  VAR PREVQTY = MAXX(FILTER(PO_PurchaseOrderDetail,[PurchaseOrderNo] = PREVPO),[QuantityOrdered])
  VAR Req = MAXX(FILTER(PO_PurchaseOrderDetail,[PurchaseOrderNo] = PO),[RequiredDate])
  VAR PREVREQ = MAXX(FILTER(PO_PurchaseOrderDetail,[PurchaseOrderNo] = PREVPO),[RequiredDate])
RETURN
  IF ( [QTYAvailable_SumFinal] < 0 && Qty < ABS([QTYAvailable_SumFinal]),  Rec & " " &PO & " " & Qty & "pcs " & Req & " " & PREVREC & " " & PREVPO & " " & PREVQTY & "pcs " & " " & PREVREQ,  Rec & " " & PO & " " & Qty & "pcs " & Req )

& another

SplitPO = 
  VAR PO = MAX(PO_PurchaseOrderDetail[PurchaseOrderNo])
  VAR RowCount = CALCULATE(COUNTROWS(PO_PurchaseOrderDetail),
                    PO_PurchaseOrderDetail[PurchaseOrderNo] = PO)
  VAR FirstReq = MINX(FILTER(PO_PurchaseOrderDetail,PO_PurchaseOrderDetail[PurchaseOrderNo] = PO),[RequiredDate])
  VAR Qty = MAXX(FILTER(PO_PurchaseOrderDetail,PO_PurchaseOrderDetail[PurchaseOrderNo] = PO && FirstReq = PO_PurchaseOrderDetail[RequiredDate] ),[QuantityOrdered])
  VAR SecondReq = MINX(FILTER(PO_PurchaseOrderDetail,PO_PurchaseOrderDetail[PurchaseOrderNo] = PO && PO_PurchaseOrderDetail[RequiredDate] > FirstReq ),[RequiredDate])
  VAR SecondQTY = MAXX(FILTER(PO_PurchaseOrderDetail,PO_PurchaseOrderDetail[PurchaseOrderNo] = PO && SecondReq = PO_PurchaseOrderDetail[RequiredDate] ),[QuantityOrdered])
RETURN
  PO & " " & FirstReq & " " & Qty & "pcs" & " " & RowCount & " " & " || " & SecondReq & " " & PO & " " & SecondQTY & "pcs"


I basically need to combine these two and have a check at the top that checks the RowCount variable. If it is >1, then I need it to run the SplitPO measure. If it is just 1 row, then it can run the SinglePOs measure. Is this possible to do?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @CalebR ,

 

Please try this measure.

Measure =
VAR RowCount =
    CALCULATE (
        COUNTROWS ( PO_PurchaseOrderDetail ),
        PO_PurchaseOrderDetail[PurchaseOrderNo] = PO
    )
VAR result =
    SWITCH ( TRUE (), RowCount > 1, [SplitPO], 1, [SinglePOs] )
RETURN
    result

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @CalebR ,

 

Please try this measure.

Measure =
VAR RowCount =
    CALCULATE (
        COUNTROWS ( PO_PurchaseOrderDetail ),
        PO_PurchaseOrderDetail[PurchaseOrderNo] = PO
    )
VAR result =
    SWITCH ( TRUE (), RowCount > 1, [SplitPO], 1, [SinglePOs] )
RETURN
    result

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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
Top Kudoed Authors