Power Bi how to meke continuous exceed 4 days (positive), will automatic show total Positive days

pychin

New Member
Joined
Jun 5, 2019
Messages
8
[FONT=&quot]Hi all[/FONT]

[FONT=&quot]At Power Bi how to make it?[/FONT]

[FONT=&quot]If the customer have positive for continuous 4 days, will automatic show how many days.No matter on which day, as long as continuous 4 days.[/FONT]

[FONT=&quot]example 1: kent continuous already exceed 4 days (positive) , he total got 6 days (positive). then automatic show me 6 days...[/FONT]

[FONT=&quot]example 2: ABBY total got 5 days (positive), but she is not continuous 5 days (positive), so just show me 0[/FONT]

[FONT=&quot]Thanks[/FONT]

sample:

this is data
DateNameValue
1/5/2019

<tbody>
</tbody>
kent

<tbody>
</tbody>
2,000.00

<tbody>
</tbody>
1/5/2019
ABBY

<tbody>
</tbody>
1,000.00

<tbody>
</tbody>
1/5/2019
HADYN

<tbody>
</tbody>
5,439.00

<tbody>
</tbody>
1/5/2019
MISSY

<tbody>
</tbody>
321.00

<tbody>
</tbody>
1/5/2019
TORI

<tbody>
</tbody>
-1,233.00

<tbody>
</tbody>
1/5/2019
Jackie

<tbody>
</tbody>
323.00

<tbody>
</tbody>
2/5/2019

<tbody>
</tbody>
kent

<tbody>
</tbody>
2,000.00

<tbody>
</tbody>
2/5/2019

<tbody>
</tbody>
ABBY

<tbody>
</tbody>
-2,315.00

<tbody>
</tbody>
2/5/2019

<tbody>
</tbody>
HADYN

<tbody>
</tbody>
8,282.00

<tbody>
</tbody>
3/5/2019

<tbody>
</tbody>
HADYN

<tbody>
</tbody>
1,222.00

<tbody>
</tbody>
3/5/2019

<tbody>
</tbody>
MISSY

<tbody>
</tbody>
3,212.00

<tbody>
</tbody>
3/5/2019

<tbody>
</tbody>
TORI

<tbody>
</tbody>
231.00

<tbody>
</tbody>
3/5/2019

<tbody>
</tbody>
kent

<tbody>
</tbody>
1,020.00

<tbody>
</tbody>
3/5/2019

<tbody>
</tbody>
ABBY

<tbody>
</tbody>
1,234.00

<tbody>
</tbody>
4/5/2019

<tbody>
</tbody>
kent

<tbody>
</tbody>
3,201.00

<tbody>
</tbody>
4/5/2019

<tbody>
</tbody>
ABBY

<tbody>
</tbody>
234.00

<tbody>
</tbody>
4/5/2019

<tbody>
</tbody>
HADYN

<tbody>
</tbody>
9,836.00

<tbody>
</tbody>
5/5/2019

<tbody>
</tbody>
kent

<tbody>
</tbody>
888.00

<tbody>
</tbody>
5/5/2019

<tbody>
</tbody>
ABBY

<tbody>
</tbody>
223.00

<tbody>
</tbody>
5/5/2019

<tbody>
</tbody>
HADYN

<tbody>
</tbody>
121.00

<tbody>
</tbody>
6/5/2019

<tbody>
</tbody>
HADYN

<tbody>
</tbody>
332.00

<tbody>
</tbody>
6/5/2019

<tbody>
</tbody>
kent

<tbody>
</tbody>
8,765.00

<tbody>
</tbody>
6/5/2019

<tbody>
</tbody>
ABBY

<tbody>
</tbody>
-1,222.00

<tbody>
</tbody>
7/5/2019

<tbody>
</tbody>
ABBY

<tbody>
</tbody>
123.00

<tbody>
</tbody>

<tbody>
</tbody>


i want the result to be like this
Name

<tbody>
</tbody>
continuous 4days

<tbody>
</tbody>
kent

<tbody>
</tbody>
6
ABBY

<tbody>
</tbody>
0
HADYN

<tbody>
</tbody>
6
MISSY

<tbody>
</tbody>
0
TORI

<tbody>
</tbody>
0
Jackie

<tbody>
</tbody>
0

<tbody>
</tbody>
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try that code
Code:
let    Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
    Changed_type = Table.Buffer(Table.TransformColumnTypes(Source,{{"Date", type date}})),
    Sorted_lines = Table.Sort(Changed_type,{{"Name", Order.Ascending}, {"Date", Order.Descending}}),
    added_Idx = Table.AddIndexColumn(Sorted_lines, "Index", 0, 1),
    Userdefined_Col = Table.AddColumn(added_Idx, "hlp", 
     each if   [Amount] < 0 then 0 else
          if   [Index] = 0 or [Name] <> added_Idx[Name]{[Index]-1} 
          then 1 
          else null),
    Fill_down = Table.FillDown(Userdefined_Col,{"hlp"}),
    Filtered_Lines = Table.SelectRows(Fill_down, each ([hlp] = 1)),
    FGrouped_Lines = Table.Group(Filtered_Lines, {"Name"}, {{"Anzahl", each Table.RowCount(_), type number}}),
    Replace_value = Table.ReplaceValue(FGrouped_Lines,1,0,Replacer.ReplaceValue,{"Anzahl"}),
    Replace_value_2 = Table.ReplaceValue(Replace_value,2,0,Replacer.ReplaceValue,{"Anzahl"}),
    Replaced_value_3 = Table.ReplaceValue(Replace_value_2,3,0,Replacer.ReplaceValue,{"Anzahl"}),
    Renamed_columns = Table.RenameColumns(Replaced_value_3,{{"Anzahl", "Continuous 4days"}}),
    Sorted_lines_2 = Table.Sort(Renamed_columns,{{"Name", Order.Ascending}})
in
    Sorted_lines_2
 
Upvote 0
Try that code
Code:
let    Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
    Changed_type = Table.Buffer(Table.TransformColumnTypes(Source,{{"Date", type date}})),
    Sorted_lines = Table.Sort(Changed_type,{{"Name", Order.Ascending}, {"Date", Order.Descending}}),
    added_Idx = Table.AddIndexColumn(Sorted_lines, "Index", 0, 1),
    Userdefined_Col = Table.AddColumn(added_Idx, "hlp", 
     each if   [Amount] < 0 then 0 else
          if   [Index] = 0 or [Name] <> added_Idx[Name]{[Index]-1} 
          then 1 
          else null),
    Fill_down = Table.FillDown(Userdefined_Col,{"hlp"}),
    Filtered_Lines = Table.SelectRows(Fill_down, each ([hlp] = 1)),
    FGrouped_Lines = Table.Group(Filtered_Lines, {"Name"}, {{"Anzahl", each Table.RowCount(_), type number}}),
    Replace_value = Table.ReplaceValue(FGrouped_Lines,1,0,Replacer.ReplaceValue,{"Anzahl"}),
    Replace_value_2 = Table.ReplaceValue(Replace_value,2,0,Replacer.ReplaceValue,{"Anzahl"}),
    Replaced_value_3 = Table.ReplaceValue(Replace_value_2,3,0,Replacer.ReplaceValue,{"Anzahl"}),
    Renamed_columns = Table.RenameColumns(Replaced_value_3,{{"Anzahl", "Continuous 4days"}}),
    Sorted_lines_2 = Table.Sort(Renamed_columns,{{"Name", Order.Ascending}})
in
    Sorted_lines_2


hi pinarello, thanks for your help...can you send me that sample power bi file?
 
Upvote 0
When re-testing, I noticed that the query did not return correct results in all cases. After the modification of the query, it should be correct now

Link to my OneDrive file


why i can't open it?

when i download and open, there show me
Excel PQ - Power Bi how to meke continuous exceed 4 days (positive) is corrupt an invalid report file
 
Upvote 0
I have now tested the link from my company laptop and was able to open, download and edit the folder without any problems.


In another thread sandy666 could probably open my folder, which I had created with my German Excel version (Office 365
 
Upvote 0
I have now tested the link from my company laptop and was able to open, download and edit the folder without any problems.


In another thread sandy666 could probably open my folder, which I had created with my German Excel version (Office 365

now i can open already...thanks

this you make by power bi or excel power query?
 
Upvote 0
I used Power Query in Excel. But with only a few exceptions, Power Query should be identical in Excel and Power BI
 
Upvote 0
I used Power Query in Excel. But with only a few exceptions, Power Query should be identical in Excel and Power BI


when i key this code got error...

if [Value] < 0 then 0 else if [Index] = 0 or [Name] <> added_Idx[Name]{[Index]-1} or [Value] > 0 then 1 else null

show me (Expression.Error: The name 'added_Idx' wasn't recognized. Make sure it's spelled correctly)
 
Upvote 0

Forum statistics

Threads
1,214,531
Messages
6,120,073
Members
448,943
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top