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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
vinicius_ramos
Helper III
Helper III

Accumulated count of the last 07 days

Hello friends, Can someone help me?

 

I need to do a count logs number in the last 07 days, how can i do this in power query? Every day my base is updated.

 

In my example, i need to count de collumn conteudo in the last 07 days.

 

vinicius_ramos_0-1627332464244.png

how can i do this?

 

Thanks a lot !

1 ACCEPTED SOLUTION

Hi  @vinicius_ramos ,

 

Using below M codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdA9DoJAGIThu3w1CewooiWgovjbk73/NQwms04xsZs83bzLEimq6OrU1miw7j5yVXRHHVQ76qi6px5VD9STKBrqWTVRJ1VQL6ob6lV1S51Vy7ebavl2Vy3fHl+FrQNbB7YObB3YOrB1YOvA1oGtA1sHtg5sHfyp89On1ZfVd+T8AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t, Conteudo = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", Int64.Type}, {"Date", type date}, {"Conteudo", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Duration.Days(Date.From(DateTime.LocalNow())-[Date])<=7 then "OK" else "Problem")
in
    #"Added Custom"

And you will see that once the date is over 7 days since now,you will get problem,else ok.

vkellymsft_0-1627540474156.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

13 REPLIES 13
vinicius_ramos
Helper III
Helper III

Hello, @Vera_33

 

Here is other print:

 

vinicius_ramos_0-1627388620986.png

 

I want do count the collunm conteudo, in the last 07 days. For Example: 

In short, i have this database:

DateConteudo
2021-07-15A
2021-07-16B
2021-07-17C
2021-07-18D
2021-07-19E
2021-07-20F
2021-07-21G
2021-07-22H
2021-07-23I
2021-07-24J
2021-07-25K
2021-07-26L
2021-07-27M

 And i need count the cells that are not blank in the last 07 days, just count from the 20th onwards. How i can do this?

 

Thanks a lot!

Hi @vinicius_ramos 

 

You want to get the Count in Power Query? I feel like you need it in a visual with a DAX measure...and if you have the same value in the column, you need to count all rows or distinct?

 

Here is one way in M, do not count distinct value, if you need, go List.Distinct that column

Vera_33_0-1627390705024.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc63DcAwDATAXVgLEEUH2aVznkDg/mvY8DffXnWlSGqi5mhqSYIM4uGjlmgEZaIJ1BHNoJ5o+cmUaAUlog1kRDuoIjpANdEJ4v0F4v0N4v0j7i8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Conteudo = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Conteudo", type text}}),
    #"Filtered Rows" = Table.RowCount( Table.SelectRows(#"Changed Type", each Date.IsInPreviousNDays([Date], 7) and [Conteudo]<>""))
in
    #"Filtered Rows"

 

But I really think you need DAX...and you need to consider if you need Distinct, and your Date will be greater than today or not

Vera_33_1-1627390819590.png

test = COUNTROWS(FILTER(yourTable,yourTable[Date]>=TODAY()-7&&yourTable[Conteudo]<>BLANK()))

 

Hi, @Vera_33 

 

I dont need count distinct, i need count all. The exemple that you give to me, its all right. Now i have another challenge. 

 

NameDateConteudo
12021-07-15A
12021-07-16B
12021-07-17C
12021-07-18D
12021-07-19E
12021-07-20F
12021-07-21G
12021-07-22H
12021-07-23I
12021-07-24J
12021-07-25K
12021-07-26L
12021-07-27M
22021-07-15A
22021-07-16B
22021-07-17C
22021-07-18D
22021-07-19E
22021-07-20F
22021-07-21G
22021-07-22H
22021-07-23I
22021-07-24J
22021-07-25K
22021-07-26L
22021-07-27M
22021-07-27N
22021-07-27O
22021-07-27P

 

I need a validation, that bring to me the count of the last 07 days per item in the "name" column, if it is greater than 07 = "Problem", else "OK".

 

Note that he should check this every date, I can do a collunm if this validation?

 

Thanks !

Hi  @vinicius_ramos ,

 

Using below M codes:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdA9DoJAGIThu3w1CewooiWgovjbk73/NQwms04xsZs83bzLEimq6OrU1miw7j5yVXRHHVQ76qi6px5VD9STKBrqWTVRJ1VQL6ob6lV1S51Vy7ebavl2Vy3fHl+FrQNbB7YObB3YOrB1YOvA1oGtA1sHtg5sHfyp89On1ZfVd+T8AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t, Conteudo = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", Int64.Type}, {"Date", type date}, {"Conteudo", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Duration.Days(Date.From(DateTime.LocalNow())-[Date])<=7 then "OK" else "Problem")
in
    #"Added Custom"

And you will see that once the date is over 7 days since now,you will get problem,else ok.

vkellymsft_0-1627540474156.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hi @vinicius_ramos 

 

So if you check today 2021-07-27, you count from 2021-07-20, do you count today as well? If not, all ok for your sample. You can modify accordingly

 

Vera_33_0-1627394305892.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddBNDoJAGIPhu3xrEmaqiC4BRcXfPZn7X8NIjK1JXfbZ9Z3nyFFFburU1kh4jy5K9eGNcE9uhQfyVnhP3gkfvowkPJKz8JEM4RN5JXwmr4Unsr68kPXllawvbwvDp4JPBZ8KPhV8KvhU8KngU8Gngk8Fnwo+Ff6n+uG754fnZ5TyAg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t, Conteudo = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", Int64.Type}, {"Date", type date}, {"Conteudo", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Changed Type", {"Name"}, "all", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each [alltable=[all],
start=Date.AddDays([Date],-7),
end=[Date],
result= 
if Table.RowCount( Table.SelectRows(alltable, each ([Date]>= start and [Date] < end and [Conteudo]<>"")))>7 then "Problem" else "OK"  ][result])
in
    #"Added Custom"

 

Hi @vinicius_ramos 

 

So if you check today 2021-07-27, you count from 2021-07-20, do you count today as well? If not, all ok for your sample. You can modify accordingly

 

Vera_33_0-1627394305892.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddBNDoJAGIPhu3xrEmaqiC4BRcXfPZn7X8NIjK1JXfbZ9Z3nyFFFburU1kh4jy5K9eGNcE9uhQfyVnhP3gkfvowkPJKz8JEM4RN5JXwmr4Unsr68kPXllawvbwvDp4JPBZ8KPhV8KvhU8KngU8Gngk8Fnwo+Ff6n+uG754fnZ5TyAg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t, Conteudo = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", Int64.Type}, {"Date", type date}, {"Conteudo", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Name"}, #"Changed Type", {"Name"}, "all", JoinKind.LeftOuter),
    #"Added Custom" = Table.AddColumn(#"Merged Queries", "Custom", each [alltable=[all],
start=Date.AddDays([Date],-7),
end=[Date],
result= 
if Table.RowCount( Table.SelectRows(alltable, each ([Date]>= start and [Date] < end and [Conteudo]<>"")))>7 then "Problem" else "OK"  ][result])
in
    #"Added Custom"

 

Vera_33
Resident Rockstar
Resident Rockstar

Hi @vinicius_ramos 

 

I want to help but I can't see your pic clearly. Would you provide some sample data and expected result in a format which people can copy?

No, maybe I'm having a difficulty making you understand what I need.

Hi @vinicius_ramos 

 

Can you explain what you want? Maybe go draw some data in Excel to present the result you want?

Hi @vinicius_ramos ,

 

Have you checked my reply?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

@v-kelly-msft 

 

Hello, yes i check.

 

But is not what i want.

 

I try to explain again

Hi @vinicius_ramos ,

 

OK,waiting for your update.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

@v-kelly-msft 

 

Hello, 

 

I will explain my real situation, i have this base assuming today is the 4th of july:

 

Dataprazadomiciliotvid_eventoconteudo
01/07/2021110107169DataBaseManager
01/07/202111098007169RestartManager
01/07/202111098007169resolvetopo
02/07/202111098107169RestartManager
03/07/202111098307169RestartManager
01/07/202111098307169gerenciadorpacotes485
01/07/20211101066807169GeradorRegistrosDIB6
02/07/20211101066807169gerenciadorpacotes485
01/07/20211101070007169meter2net
02/07/20211101070007169gerenciadorfgp
02/07/20211101070007169agc
03/07/20211101070007169identificador_perifericos
03/07/20211101070007169sampler2
01/07/20211101071417169resolvetopo
01/07/20211101071607169meter2net
03/07/20211101071607169meter2net
02/07/20211101071607169meter2net
01/07/20211101075107169meter2net
01/07/20211101075107169meter2net
01/07/20211101075107169meter2net

 

The collunm "conteudo" represents which the application reset and collunm "domicilio" represents the place. I need to count how many resets were done in the last 03 days and if there were more than 03 resets in the last 03 days = "Problem" if less than 03 resets = "OK".

I choose one domicilio to example:

domicilionumbers of reset  in the last 03 days ( count "conteudo")validation
107005Problem

 

I need a column to do this process and return me if there is a problem or OK.

 

Can you help me?

 


thank you for the patience

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors