Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Nickolay1
Contributor III
Contributor III

Count number of values below the current line based on a condition

Dear Community,

Hopefully you will be able to help with this one. I need to calculate number of months that Projected Total Stock in the table below can cover. In this example the projected stock is available from July till September. Therefore the coverage in July should be 3 months, August - months ,September - 1 month and from October - 0 as shown in the column Months covered in the table below. 

Data Month - Year Material Number Projected Total Stock Months covered
01.07.2023 153815 1152750 3
01.08.2023 153815 1152750 2
01.09.2023 153815 1152750 1
01.10.2023 153815 0 0
01.11.2023 153815 0 0
01.12.2023 153815 0 0
01.01.2024 153815 0 0

 

Thank you!
 

Labels (4)
1 Solution

Accepted Solutions
Lokesh_5045
Creator
Creator

I can suggest a way. Sort the table in reverse order based on date.

If(Material = Peek(Material) and Projected_Stock > 0, RangeSum(Peek(Months_covered) + 1), 0) as Months_covered

Lokesh_5045_0-1689947419527.png

Then if you want in previous order, then again reverse the order of the table based on date.
Based on this idea, if you can solve it in better way, please post it here.

View solution in original post

1 Reply
Lokesh_5045
Creator
Creator

I can suggest a way. Sort the table in reverse order based on date.

If(Material = Peek(Material) and Projected_Stock > 0, RangeSum(Peek(Months_covered) + 1), 0) as Months_covered

Lokesh_5045_0-1689947419527.png

Then if you want in previous order, then again reverse the order of the table based on date.
Based on this idea, if you can solve it in better way, please post it here.