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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
RodolfoGuti
Regular Visitor

Tengo problemas con una formula DAX

Dias_Stock_Enero =
VAR __i = 31
VAR __loopTable = GENERATESERIES(1,__i)
VAR __loopTable1 = ADDCOLUMNS(__loopTable,"__i",Date(2020,1,[Value]))
VAR __loopTable2 = ADDCOLUMNS(__loopTable1,"sum",SUMX(FILTER(Query1,[DocDate]<=[__i]),[cantidad]))
VAR __loopTable3 = ADDCOLUMNS(__loopTable2,"cant",COUNTX(FILTER(__loopTable2,[sum]>0),2))
RETURN
COUNTX(__loopTable3,[cant])
 
Requiero contar los dias en los que el stock fue mayor que Cero. para sacar un promedio simple

ya pude sumar el stock diariamente con la formula:
 
Inventario_Enero =
VAR __i = 31
VAR __loopTable = GENERATESERIES(1,__i)
VAR __loopTable1 = ADDCOLUMNS(__loopTable,"__i",Date(2020,1,[Value]))
VAR __loopTable2 = ADDCOLUMNS(__loopTable1,"haj",SUMX(FILTER(Query1,[DocDate]<=[__i]),[cantidad]))
RETURN
SUMX(__loopTable2,[haj])
imagen.png
1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @RodolfoGuti ,

 

Or like this?

Dias_Stock_Enero =
VAR __i = 31
VAR __loopTable = GENERATESERIES(1,__i)
VAR __loopTable1 = ADDCOLUMNS(__loopTable,"__i",Date(2020,1,[Value]))
VAR __loopTable2 = ADDCOLUMNS(__loopTable1,"sum",SUMX(FILTER(Query1,[DocDate]<=[__i]),[cantidad]))
VAR __loopTable3 = ADDCOLUMNS(__loopTable2,"cant",COUNTX( FILTER(__loopTable2,[sum]>0), [sum]) )
RETURN
SUMX(__loopTable3,[cant])

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-lionel-msft
Community Support
Community Support

Hi @RodolfoGuti ,

 

Or like this?

Dias_Stock_Enero =
VAR __i = 31
VAR __loopTable = GENERATESERIES(1,__i)
VAR __loopTable1 = ADDCOLUMNS(__loopTable,"__i",Date(2020,1,[Value]))
VAR __loopTable2 = ADDCOLUMNS(__loopTable1,"sum",SUMX(FILTER(Query1,[DocDate]<=[__i]),[cantidad]))
VAR __loopTable3 = ADDCOLUMNS(__loopTable2,"cant",COUNTX( FILTER(__loopTable2,[sum]>0), [sum]) )
RETURN
SUMX(__loopTable3,[cant])

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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