简体   繁体   中英

DAX - Filter between two specified dates

  1. Table 1 (Combined Hours) I have a list of [payweek], which is many repeated组合表的图像

  2. Table 2 (All Scripts), I have a list of jobs and two dates, [Scripting Date] and [R4PreScriptDate]图像如果所有脚本表

  3. I am trying to find the number of unique [payweek]s between the [Scripting Date] and the [R4PreScriptDate]

  4. The DAX formula is below. My result is always 3. However, I am expecting variable answers (0,1, 2,3,4 or 5)

     R4PreScriptWkCt = CALCULATE(DISTINCTCOUNTNOBLANK(CombinedHours[payWeek]),FILTER(CombinedHours, CombinedHours[payWeek] <= MAX (AllScripts[Scripting Date] ) && CombinedHours[payWeek] >= MAX (AllScripts[R4PreScriptDate] ) ))

Thank you,

I assumed that both tables are related by Job Number. I created the following measure:

R4PreScriptWkCt =
VAR __date2 = MAX ( AllScripts[R4PreScriptDate] )
VAR __date1 = MAX ( AllScripts[Scripting Date] )
VAR __job = MAX ( AllScripts[Job Number] )
VAR __subTable =
    FILTER (
        CombinedHours,
        CombinedHours[Job Number] = __job
            && CombinedHours[Week] >= __date1
            && CombinedHours[Week] <= __date2
    )
RETURN
    CALCULATE ( DISTINCTCOUNTNOBLANK ( CombinedHours[Week] ), __subTable )

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM