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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DaanBos
Frequent Visitor

Count occurrences until certain value

Dear all,

 

I want to count the iterations required to get an amount of 50 throughput. Below is the code I created. But the problem now is that it gives the same value in the entire column. Does anyone know the answer?

CountIt = 
VAR RandomIterations = 0
VAR TotalThroughput = 0
VAR ThroughputNeeded = 50
VAR RandomThroughput = CALCULATE(
    VALUES('Iterties'[Throughput]),
    FILTER(
        'Iterties',
        'Iterties'[Iteratie] = EARLIER(Monte_Carlo_Simulation[Random]) --ROUND(RANDBETWEEN(1, COUNTROWS(Iterties)), 0)--
    )
)
VAR UpdatedTotalThroughput = TotalThroughput + RandomThroughput

RETURN
IF(
    UpdatedTotalThroughput < ThroughputNeeded,
    COUNTAX(VALUES('Iterties'[Iteratie]), 1),
    0
)

 

DaanBos_0-1703150269138.png

Greets,

Daan

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @DaanBos ,

Could you share the expected output? This would be helpful in solving the question.
thanks.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

DaanBos
Frequent Visitor

In the meantime, they have come up with a measure that seems to work, but with the wrong results.
Here's the code:

CountItmes = 
CALCULATE(
    COUNTAX(
        VALUES('Iterties'[Iteratie]),
        VAR RandomSelection = RANDBETWEEN(1, COUNTROWS(VALUES('Iterties'[Iteratie])))
        VAR ThroughputNeeded = 20
        RETURN
        IF (
            SUMX(
                FILTER(
                    'Iterties',
                    RANKX(VALUES('Iterties'[Iteratie]), 'Iterties'[Iteratie], , ASC) <= RandomSelection
                ),
                'Iterties'[Throughput]
            ) >= ThroughputNeeded,
            1
        )
    )
)

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.