Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

How to create an array and loop in DAX

I have a large amount of data with a lot of different work centers, but I want to calculate workcenter1(good parts/total parts) * workcenter2(good parts/total parts) * ... but only for a certain list...
  • ValtteriN's avatar
    2 years ago

    Hi,

    I would recommend using PRODUCTX function:

    test data:
    Here the goal is to have your logic applied for cost centers A,B and D. The result would be (1/2)*(2/2)*(1/2)

    Here is the dax:

    Measure 22 =

    var _workcenters = {"A","B","D"}

    RETURN
    PRODUCTX(
    ADDCOLUMNS(
    SUMMARIZE(FILTER('Table (31)','Table (31)'[Workcenter] in _workcenters),'Table (31)'[Workcenter]),"good/all",
    CALCULATE(COUNT('Table (31)'[ID]),'Table (31)'[Goodpart]=1)/
    CALCULATE(COUNT('Table (31)'[ID])))
    ,[good/all])


    End result:

    I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

    My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/

  • tamerj1's avatar
    2 years ago

    Hi Anonymous 

    not sire if I fully understand the requirement however please try

    Measure1 =
    PRODUCTX (
    TREATAS (
    {
    "670205",
    "670206",
    "670302",
    "670502",
    "670902",
    "670904",
    "671002",
    "671202"
    },
    DWS_ConfPassAndScrap[Workcenter]
    ),
    CALCULATE (
    DIVIDE (
    SUM ( DWS_ConfPassAndScrap[PassQuantity] ),
    SUM ( DWS_ConfPassAndScrap[PassQuantity] )
    + SUM ( DWS_ConfPassAndScrap[ScrapQuantity] )
    )
    )
    )