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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Krishna_here
Regular Visitor

How to get list of item occurance with condition

Hi All,

i have table dataset in the below format,

IDDateApp nameDuration
10001-12-2022METER10
10001-12-2022Instagram20
10101-12-2022FB20
10201-12-2022METER10
10002-12-2022METER10
10102-12-2022Whatsapp30
10202-12-2022METER10
10003-12-2022Whatsapp30
10103-12-2022METER10
10103-12-2022Instagram20
10204-12-2022METER10

 

First part was to calculate ATS = duration/distinctcount(ID) for each day excluding "METER" app. I used below DAX for the calculation

 
ATS  =
AVERAGEX
(
    SUMMARIZE(FILTER(table, table[Appname] <> "METER"), table[Date],"Sum_duration",SUM(table[Duration]),"Reach", DISTINCTCOUNT(table[ID]))
,
DIVIDE([Sum_duration],[Reach]))
 
Above DAX gave me ATS result for each day excluding "METER" app.
 
Second part of problem was to get list of ID that gives me only "METER" data for the month (all days considered). That means for the above dataset ID 102 gives "METER" data only for all the 4 days considered. Other ID reported data for other apps as well so can be excluded.  
 
Please help what DAX to use.
1 ACCEPTED SOLUTION

HI @Krishna_here,

You can use the following measure formula to check current id related records within current date ranges and return flag:

flag =
VAR currDate =
    MAX ( 'Table'[Date] )
VAR appList =
    CALCULATETABLE (
        VALUES ( 'Table'[App name] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            YEAR ( 'Table'[Date] ) = YEAR ( currDate )
                && MONTH ( 'Table'[Date] ) = MONTH ( currDate )
        ),
        VALUES ( 'Table'[ID] )
    )
RETURN
    IF ( "METER" IN appList && COUNTROWS ( appList ) = 1, "Y", "N" )

2.PNG

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
Krishna_here
Regular Visitor

Was able to solve above prob in SQL for one day taken at a time:

 

SELECT  ID

FROM tabel
WHERE Date='2022-12-01'
GROUP BY ID
HAVING MIN(app name)=MAX(app name)
AND MIN(app name) in ('METER')

 

Can somebody help the above same in DAX method ?

HI @Krishna_here,

You can use the following measure formula to check current id related records within current date ranges and return flag:

flag =
VAR currDate =
    MAX ( 'Table'[Date] )
VAR appList =
    CALCULATETABLE (
        VALUES ( 'Table'[App name] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            YEAR ( 'Table'[Date] ) = YEAR ( currDate )
                && MONTH ( 'Table'[Date] ) = MONTH ( currDate )
        ),
        VALUES ( 'Table'[ID] )
    )
RETURN
    IF ( "METER" IN appList && COUNTROWS ( appList ) = 1, "Y", "N" )

2.PNG

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you so much for the response. So i was applying the same measure that you have given but my actual dataset is huge so keeping ID, app name and date is not loading the measure. (data that i pasted in question was just a sample).

Is it possible to show the flag against each ID in visual avoiding the app and date from the visual ?

Hi @Krishna_here,

In fact, this expression will check at the year month level based on current ID group.

If you only use ID as category without other fields, the formula will get wrong results because the aggregate row contexts have matched with multiple type of flags.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors