Forum Discussion

SKC18's avatar
SKC18
Frequent Visitor
1 year ago

Turning Measure into Column

Fill Category Measure =
VAR DaysDifference = [Days Between Fills] -- Reference your average days between fills measure
RETURN
    SWITCH(
        TRUE(),
        ISBLANK(DaysDifference), "No Data",
        DaysDifference <= 5, "Less than or equal to 5 days",
        DaysDifference > 5 && DaysDifference <= 30, "6 to 30 days",
        DaysDifference > 30 && DaysDifference <= 60, "31 to 60 days",
        DaysDifference > 60 && DaysDifference <= 90, "61 to 90 days",
        DaysDifference > 90, "Greater than 90 days",
        "Unknown"
this above code dynamically changes arrording to date range with the day between fill =
VAR CurrentDay = MAX(FillEfficiency[Day]) -- Maximum day in the current filter context
VAR CurrentAsset = SELECTEDVALUE(FillEfficiency[asset_name]) -- Single value for the current asset
VAR PreviousFillDate =
    CALCULATE(
        MAX(FillEfficiency[Day]),
        FillEfficiency[asset_name] = CurrentAsset, -- Same asset
        FillEfficiency[Day] < CurrentDay -- Earlier dates only
    )
RETURN
    IF(
        ISBLANK(CurrentAsset) || ISBLANK(PreviousFillDate),
        BLANK(), -- No previous fill exists
        DATEDIFF(PreviousFillDate, CurrentDay, DAY)
    ) But I want a column for it so that it can show the number of asset in a particular area of fill date  

But as it is a measure the results are only showing up like this 

 

3 Replies

  • Hi SKC18  - you can create a  new calculated column in your table: replace with your table name and fields. 

     

     

     

    DaysBetweenCategory =
    VAR CurrentDay = FillEfficiency[Day] -- Current day for each row
    VAR CurrentAsset = FillEfficiency[asset_name] -- Asset for each row
    VAR PreviousFillDate =
        CALCULATE(
            MAX(FillEfficiency[Day]),
            FILTER(
                FillEfficiency,
                FillEfficiency[asset_name] = CurrentAsset &&
                FillEfficiency[Day] < CurrentDay
            )
        )
    VAR DaysDifference =
        IF(
            ISBLANK(CurrentAsset) || ISBLANK(PreviousFillDate),
            BLANK(), -- No previous fill exists
            DATEDIFF(PreviousFillDate, CurrentDay, DAY)
        )
    RETURN
        SWITCH(
            TRUE(),
            ISBLANK(DaysDifference), "No Data",
            DaysDifference <= 5, "Less than or equal to 5 days",
            DaysDifference > 5 && DaysDifference <= 30, "6 to 30 days",
            DaysDifference > 30 && DaysDifference <= 60, "31 to 60 days",
            DaysDifference > 60 && DaysDifference <= 90, "61 to 90 days",
            DaysDifference > 90, "Greater than 90 days",
            "Unknown"
        )
    • SKC18's avatar
      SKC18
      Frequent Visitor

      This is the thing that I did in the next step to find the solution but if same assets repeats in a date then same asset name will have different frequency of the day between fill 

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi SKC18 

         

        Could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution.

        You can refer the following links to share the required info:

        How to provide sample data in the Power BI Forum

        How to Get Your Question Answered Quickly

        And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

        How to upload PBI in Community

         

        Best Regards

        Zhengdong Xu
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.