Forum Discussion

Si_7777's avatar
Si_7777
Icon for Advocate II rankAdvocate II
1 year ago
Solved

DAX help - counting single item lines

I have  measure to count PO's with single items

 

It kinda works but doesnt sum per day / week / per year

 

 

My measure is ; 

1 Items per PO =
    CALCULATE(COUNTROWS(Sage_POPOrderReturnLine)
    , FILTER(Sage_POPOrderReturnLine, DISTINCTCOUNT(Sage_POPOrderReturnLine[ItemCode]) = 1))
 
I have tried summerize but I am not getting the syntax correct.

 

 

  • Hi Si_7777 , Thank you for reaching out to the Microsoft Community Forum.

     

    We took sample data based on your scenario and recreated your matrix structure with Year -> Date -> PO Number. We rewrote the 1 Items per PO measure to first identify POs that have exactly one distinct item, then count them in the current filter context. This ensures the count is accurate at PO, daily and yearly levels without double-counting.

     

    Please check the attached .pbix file for your reference and share your thoughts.

     

    Thank you.

5 Replies

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Si_7777 , Thank you for reaching out to the Microsoft Community Forum.

     

    We took sample data based on your scenario and recreated your matrix structure with Year -> Date -> PO Number. We rewrote the 1 Items per PO measure to first identify POs that have exactly one distinct item, then count them in the current filter context. This ensures the count is accurate at PO, daily and yearly levels without double-counting.

     

    Please check the attached .pbix file for your reference and share your thoughts.

     

    Thank you.

  • Wilson_'s avatar
    Wilson_
    Icon for Memorable Member rankMemorable Member

    Hi Si_7777,

     

    The main issue is you need it to check for 1 item on the PO by day and order, before rolling it up to the different levels in your hierarchy. However, the way your measure is written, it is, for example, checking for 1 item on the PO for the whole year at the top level in your matrix.

     

    Try something like:

     

    1 Item per PO =
    VAR _Summarized =
        FILTER (
            SUMMARIZE (
                Dates[Year], -- first field in your matrix row hierarchy
                Dates[Month], -- second field in your matrix row hierarchy
                Dates[Date], -- third field in your matrix row hierarchy
                Sage_POPOrderReturnLine[POPOrderNumber] -- fourth field in your matrix row hierarchy
            ),
            CALCULATE ( DISTINCTCOUNT ( Sage_POPOrderReturnLine[ItemCode] ) = 1
        )
    VAR _Result = COUNTROWS ( _Summarized )
    
    RETURN _Result

     ----------------------------------
    If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

     

    P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Si_7777 , hope you are doing great. May we know if your issue is solved or if you are still experiencing difficulties. Please share the details as it will help the community, especially others with similar issues.

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Si_7777 , Hope you are doing well. Kindly let us know if the issue has been resolved or if further assistance is needed. Your input could be helpful to others in the community.

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi Si_7777 , Hope you're doing fine. Can you confirm if the problem is solved or still persists? Sharing your details will help others in the community.