Forum Discussion

Tiger2514555's avatar
Tiger2514555
Helper III
2 years ago
Solved

Get max multiple selected value from slice

I chose weeks 44 and 42, which would be 2 if it was the highest week. Less than 3 I don't understand why my data where weeks are less than weeks maximum doesn't meet the 3 criteria if weeks are less than weeks maximum.
Right result (But not DAX for multiple selected value from slicer):

 

My DAX Measure

Check Measure =
VAR FilteredTable =
    FILTER(
        'DemandSummaryAPS',
        'DemandSummaryAPS'[demandID] = ('DemandSummaryAPS'[demandID]) &&
        'DemandSummaryAPS'[item] = ('DemandSummaryAPS'[item]) &&
        'DemandSummaryAPS'[Week Num Due] = ('DemandSummaryAPS'[Week Num Due]) &&
        'DemandSummaryAPS'[demandID] <> BLANK()
    )


VAR _max_week_num =
    MAXX(FilteredTable, 'DemandSummaryAPS'[Week Create])

VAR _min_week_num =
    MINX(FilteredTable, 'DemandSummaryAPS'[Week Create])


VAR Sum_Check =
    IF(
        COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] = [Laset Week])) > 0 &&
        COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] < [Laset Week])) > 0,
        1,
        IF(
            COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] = [Laset Week])) > 0 &&
            COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create]  < [Laset Week])) = 0,
            2,
            IF(
                COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] = [Laset Week])) = 0 &&
                COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] < [Laset Week])) > 0,
                3,
                0
            )
        )
    )
RETURN
    Sum_Check



My DAX:
Laset Week =
VAR SelectedWeek = ALLSELECTED(WeekSlicer[Week Create])
VAR Max_Week =
CALCULATE(
MAXX(
FILTER(
ALLEXCEPT(
DemandSummaryAPS,
DemandSummaryAPS[demandID],
DemandSummaryAPS[item],
DemandSummaryAPS[Week Num Due]
),
DemandSummaryAPS[Week Create] IN SelectedWeek
),
DemandSummaryAPS[Week Create]
)
)
RETURN
Max_Week

  • Now I can do this, I created a new Week Create table but didn't relationship it because if I concatenate the result would be the same.
    There is a problem with LasetWeek which tells which week is the highest week.
    LasetWeek =
    VAR SelectedWeek = ALLSELECTED(WeekSlicer[Week Create])
    VAR Max_Month =
    CALCULATE(
    MAXX(
    FILTER(
    ALLNOBLANKROW(DemandSummaryAPS),
    'DemandSummaryAPS'[Week Create] IN SelectedWeek
    ),
    DemandSummaryAPS[Week Create]
    )
    )
    RETURN
    Max_Month

6 Replies

  • Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
    If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Please show the expected outcome based on the sample data you provided.

    If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

    • Tiger2514555's avatar
      Tiger2514555
      Helper III
      Week CreateiditemquantityWeek DueCheck MeasureWeek By Week
      42F01A230403-30
      44F01A22040220

      If I select the slicer Week Create 44 and 42, weeks with the highest measurement value must be 2, and weeks less than the highest will be 3 and negative values. Now I'm stuck with a problem. Week values ​​that are less than my maximum week, check, measure all to 2.
      lbendlin 

  • It doesn't work. lbendlin 
    My data like this:

    Week CreateIDitemquantityWeek DueCheck MeasureWeek By Week
    42F01A230403-30
    44F01A22040220
    42F02A310413-10
    44F02A31041210
    42F05A560423-60
    44F06A65042250

    My Week By Week value comes from quantity, which is viewed from Check Measure. If it is 1, show the quantity value of the highest week minus the value of the lowest week. If it is 2, show the quantity value of the highest week. If it is 3, show the quantity value of minimal week and is a negative value Which is my Check Measure to find which data is 1,2,3 which is compared to Measure Laset Week which I use to find the highest Week Create selected from the Slicer.
    If you need the file to review, I can send it to you in a private message.

    My Check Measure :

    Check Measure =
    VAR FilteredTable =
        FILTER(
            'DemandSummaryAPS',
            'DemandSummaryAPS'[demandID] = ('DemandSummaryAPS'[demandID]) &&
            'DemandSummaryAPS'[item] = ('DemandSummaryAPS'[item]) &&
            'DemandSummaryAPS'[Week Num Due] = ('DemandSummaryAPS'[Week Num Due]) &&
            'DemandSummaryAPS'[demandID] <> BLANK()
        )
    VAR Sum_Check =
        IF(
            COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] = [Laset Week])) > 0 &&
            COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] < [Laset Week])) > 0,
            1,
            IF(
                COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] = [Laset Week])) > 0 &&
                COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create]  < [Laset Week])) = 0,
                2,
                IF(
                    COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] = [Laset Week])) = 0 &&
                    COUNTROWS(FILTER(FilteredTable, 'DemandSummaryAPS'[Week Create] < [Laset Week])) > 0,
                    3,
                    0
                )
            )
        )
    RETURN
        Sum_Check
    • lbendlin's avatar
      lbendlin
      Super User

      Your sample data is inconsistent with the code.  [Laset Week] and [demandID] are missing. 

  • Now I can do this, I created a new Week Create table but didn't relationship it because if I concatenate the result would be the same.
    There is a problem with LasetWeek which tells which week is the highest week.
    LasetWeek =
    VAR SelectedWeek = ALLSELECTED(WeekSlicer[Week Create])
    VAR Max_Month =
    CALCULATE(
    MAXX(
    FILTER(
    ALLNOBLANKROW(DemandSummaryAPS),
    'DemandSummaryAPS'[Week Create] IN SelectedWeek
    ),
    DemandSummaryAPS[Week Create]
    )
    )
    RETURN
    Max_Month