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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
KatkaS
Post Patron
Post Patron

Keep first value

Hello,

 

I have a simple excel sheets with names and dates when they logged in an application.

I need to keep (count) only their first log-in, delete the rest (or keep, but just count the first login).

 

Result will be a stacked column chart: Number of log-ins and month+year.

 

Could anyone please help?

Thank you!!

Name Logged in Result
Anna26/8/2020keep
Anna29/8/2020delete
Albert01/08/2020keep
Anna31/8/2020delete
Cecile01/01/2020keep
1 ACCEPTED SOLUTION
fhill
Resident Rockstar
Resident Rockstar

 

In Query Editor, try the Group By Feature -> Advanced to Select the MIN Login (by Email) and COUNT of Rows.

 

After that, you can take the GROUPED DATA into a simple chart.

 

fhill_0-1598451717793.png

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Logged in", type datetime}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Name", Order.Ascending}, {"Logged in", Order.Ascending}}),
    Partition = Table.Group(#"Sorted Rows", {"Name"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Logged in", "Index"}, {"Logged in", "Index"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Partition", "Action", each if [Index]=1 then "Keep" else "Delete"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

If you do not want to Load the "Delete" rows to your Data Model, then you can simply filter out those values.

Hope this helps.

Untitled.png 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
fhill
Resident Rockstar
Resident Rockstar

 

In Query Editor, try the Group By Feature -> Advanced to Select the MIN Login (by Email) and COUNT of Rows.

 

After that, you can take the GROUPED DATA into a simple chart.

 

fhill_0-1598451717793.png

 




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




@fhill THANK YOU SO MUCH, it worked!!!

Greg_Deckler
Community Champion
Community Champion

@KatkaS - Seems like:

Measure =
  VAR __Month = MAX('Calendar'[Month])
  VAR __Year = MAX('Calendar'[Year])
  VAR __Table = SUMMARIZE(ALL('Table'),[Name],"First",MIN([Logged in]))
RETURN
  COUNTROWS(FILTER(__Table,YEAR([First])=__Year && MONTH([First])=__Month))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you, Greg, but I'm afraid this is too advanced for me. You mentioned MAX('Calendar'[Month])

 - do I need to create new table with periods and create relationship between the User login table..? 

amitchandak
Super User
Super User

@KatkaS , not very clear. Do we need to calculate first log in (Logic)

 

calculate(countrows(table),filter(table, table[Result] in{"delete","First log in"}))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you, Amit. I tried your measure, but I don't understand what you mean by in{"delete","First log in"})) - do I need to add new column "First log in"..?

And yes, we need to count how many new logins were every month - month are on X axis of a stacked column chart..

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors