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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.