Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
RomanDautov88
New Member

DAX GROUP BY values with filter and condition

Hi everyone!

Need help in Dax with this implementation:
What i have: 2 tables with "Date", "Time", "NPS" (scores), "Data source" tag (both table have same columns, diffirence in Data source tag)
What i need: grouping date/time/nps and if time in 1st source >= 2nd source i need with record key (combined text with Date/phone/time for filters later).

 

Having working M-code, but cant understand Dax variant...

 M-code:

let
Source = Table.Combine({IVR,SF}),
#"Grouped Rows" = Table.Group(Source,
{"fnPhone", "Date", "NPS"},
{
{"Count", each Table.RowCount(_), Int64.Type},
{"Condition", each Table.RowCount(Table.SelectRows(_, each [Data Source] = "IVR")) > 0 and Table.RowCount(Table.SelectRows(_, each [Data Source] = "SF")) > 0, type nullable number},
{"IVR", each Table.SelectRows(_, each [Data Source] = "IVR"), type table [Time=nullable time]},
{"SF", each Table.SelectRows(_, each [Data Source] = "SF"), type table [Time=nullable time]}
}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Condition] = true)),
#"Expanded IVR" = Table.ExpandTableColumn(#"Filtered Rows", "IVR", {"Time"}, {"IVR.Time"}),
#"Expanded SF" = Table.ExpandTableColumn(#"Expanded IVR", "SF", {"Time"}, {"SF.Time"}),
#"Added Custom" = Table.AddColumn(#"Expanded SF", "Custom",
each if [SF.Time] >= [IVR.Time]
then null
else Text.Combine({Text.From([Date], "ru-RU"), Text.From([fnPhone], "ru-RU"), Text.From([IVR.Time], "ru-RU")}, "|")),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom", each [Custom] <> null and [Custom] <> "")
in
#"Filtered Rows1"

 

Data example:

Data SourcefnPhoneDateTimeNPS

SF8888888801.12.202115:47:0010
SF8888888801.12.202115:48:009
SF777777702.12.20219:48:008
SF777777703.12.20213:48:007
SF6666666601.12.20219:47:006
SF5555555501.12.20213:47:005
SF44444444401.12.20219:47:008
SF44444444401.12.20213:47:007
SF33333333301.12.202115:47:0010
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @RomanDautov88 ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Create a calculated column as below in table IVR to get the count of record which meet the special conditions

IVRCount = 
COUNTROWS (
    FILTER (
        'SF',
        'SF'[fnPhone] = 'IVR'[fnPhone]
            && 'SF'[Date] = 'IVR'[Date]
            && 'SF'[NPS] = 'IVR'[NPS]
            && 'SF'[Time] < 'IVR'[Time]
    )
)

2. Create a calculated column  in table IVR or create a calculated table to get the record key

Record Key = IF ( [IVRCount] > 0, 'IVR'[Date] & "|" & 'IVR'[fnPhone] & "|" & 'IVR'[Time] )

Create calculated columnsCreate calculated columns

Table = 
SUMMARIZE (
    FILTER ( 'IVR', 'IVR'[IVRCount] > 0 ),
    'IVR'[fnPhone],
    'IVR'[Date],
    'IVR'[NPS],
    'IVR'[Time],
    "Recordkey",
        'IVR'[Date] & "|" & 'IVR'[fnPhone] & "|" & 'IVR'[Time]
)

Create calculated tableCreate calculated table

Best Regards

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

NewTable=FILTER(GENERATE(IVR,VAR _t=FILTER(SF,SF[fnPhone]=IVR[fnPhone]&&SF[Date]=IVR[Date]&&SF[NPS]=IVR[NPS]&&SF[Time]<IVR[Time]) RETURN ROW("Key", IF(COUNTROWS(_t),IVR[Date]&"|"&IVR[fnPhone]&"|"&IVR[Time]))),[Key]<>"")

Anonymous
Not applicable

Hi @RomanDautov88 ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Create a calculated column as below in table IVR to get the count of record which meet the special conditions

IVRCount = 
COUNTROWS (
    FILTER (
        'SF',
        'SF'[fnPhone] = 'IVR'[fnPhone]
            && 'SF'[Date] = 'IVR'[Date]
            && 'SF'[NPS] = 'IVR'[NPS]
            && 'SF'[Time] < 'IVR'[Time]
    )
)

2. Create a calculated column  in table IVR or create a calculated table to get the record key

Record Key = IF ( [IVRCount] > 0, 'IVR'[Date] & "|" & 'IVR'[fnPhone] & "|" & 'IVR'[Time] )

Create calculated columnsCreate calculated columns

Table = 
SUMMARIZE (
    FILTER ( 'IVR', 'IVR'[IVRCount] > 0 ),
    'IVR'[fnPhone],
    'IVR'[Date],
    'IVR'[NPS],
    'IVR'[Time],
    "Recordkey",
        'IVR'[Date] & "|" & 'IVR'[fnPhone] & "|" & 'IVR'[Time]
)

Create calculated tableCreate calculated table

Best Regards

smpa01
Super User
Super User

@RomanDautov88  provide sample data and expected output.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.