Forum Discussion

SCNCKS1's avatar
SCNCKS1
Icon for Helper I rankHelper I
1 year ago

Limit entries on a table

I have a model that tracks date, project, production unit & foreman (amoung other things). I have a table in a report that shows all entries added together. My table is too long, so i need to reduce to show only the foreman that have performed the production unit in the past 6 months. I have tried to create a calculated column, it didn't provide a true/false for every entry - it gave me false for those that were over the 180 days and true for under 180 days. I tried a measure, but it will not add to the table or the filter part of the table.

I tried a relative filter, but I cannot filter out based strictly on the date, one of the values in the table is YTD totals for all foreman, i need that to stay the combined YTD for all foreman.

Any suggestions on the best method to accomplish this task?

 

Calculated Column - 

HasWorkedInLast6Months =
VAR ForemanID = TBL_Production[FieldEmployeeID]
VAR ProjectID = TBL_Production[ProjectID]
VAR ProductionUnitID = TBL_Production[ProductionUnitID]

-- This variable calculates if there is any row in the last 6 months with the correct conditions
VAR AnyWorkInLast6Months =
CALCULATE(
MAXX(
TBL_Production, TBL_Production[WorkDate] -- We check for the max work date within the filtered set
),
TBL_Production[FieldEmployeeID] = ForemanID, -- Filter for the same Foreman
TBL_Production[ProjectID] = ProjectID, -- Filter for the same Project
TBL_Production[ProductionUnitID] = ProductionUnitID, -- Filter for the same Production Unit
TBL_Production[WorkDate] >= TODAY() - 180 -- Only include work within the last 6 months
)

-- Return TRUE if any valid work in the last 6 months is found across all rows
RETURN IF(NOT(ISBLANK(AnyWorkInLast6Months)), TRUE(), FALSE())



Measure - 

HasWorkedInLast6MonthsMeasure =
VAR ForemanID = SELECTEDVALUE(TBL_Production[FieldEmployeeID])
VAR ProjectID = SELECTEDVALUE(TBL_Production[ProjectID])
VAR ProductionUnitID = SELECTEDVALUE(TBL_Production[ProductionUnitID])

-- Calculate if the foreman worked on this project and production unit within the last 6 months
VAR WorkInLast6Months =
CALCULATE(
MAX(TBL_Production[WorkDate]), -- Find the latest work date
TBL_Production[FieldEmployeeID] = ForemanID, -- Filter for the current foreman
TBL_Production[ProjectID] = ProjectID, -- Filter for the same project
TBL_Production[ProductionUnitID] = ProductionUnitID, -- Filter for the same production unit
TBL_Production[WorkDate] >= TODAY() - 180 -- Ensure the work date is within the last 6 months
)

-- If a valid WorkDate is found, return 1 (TRUE), otherwise return 0 (FALSE)
RETURN IF(NOT(ISBLANK(WorkInLast6Months)), 1, 0)

4 Replies

  • AllisonKennedy's avatar
    AllisonKennedy
    Icon for Community Champion rankCommunity Champion

    SCNCKS1 

     

    Why isn't your calculated column working? If it gives True for for those under 180 days, just use that as a filter on your table visualization?

     

    The blank entries will be ones that don't meet any of the criteria, but I think you should capture everything with just the TRUEs?

    • SCNCKS1's avatar
      SCNCKS1
      Icon for Helper I rankHelper I

      The first partial table is correct, when i activate the true option, i get the 2nd table. I need the YTD informaiton to include all values YTD, even if they haven't worked.

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, SCNCKS1 

    Thanks for AllisonKennedy reply. It's not clear if it meets your needs. If I were filtering data over a six month period, I'd choose to write a flag measure and put it in the Filter pane and set it to 1.



    Best Regards,
    Yang
    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

     

    • SCNCKS1's avatar
      SCNCKS1
      Icon for Helper I rankHelper I

      This has the potential to work, but my employees potentially have worked doing another task so they would be included in this report when they didn't do this task - thoughts on that?