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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Mentzer
Frequent Visitor

Counting Old Dates for a Specific Condition

Hello people,

 

How can I deal with the following situation? I have Table1 that has all the Groups that certain ID has gone through. The Table2 has the quantity of distinct Groups that the ID has gone through.

 

For example, ID=13 from Table1, we can see that it has made 4 group change (G-H-G-A), but we can say that it went through only 3 groups, (G-H-A) and that's what Table2 say to us.

 

Let's suppose that this table is always updated with new IDs.

 

Mentzer_1-1664811966794.png

 

 

So, how can I count the Groups from IDs that have a Changed Group > 1 and count only the group in the oldest Date? So, in this hypothetical case, we would count only the oldest groups from ID 10, 13 and 20.

 

Mentzer_2-1664812435908.png

 

I am very grateful for your attention.

 

 

1 ACCEPTED SOLUTION

Hi @Mentzer ,

 

Here I suggest you to try this code to create a calculated column.

Count Group in Oldest Date = 
VAR _Oldest_Date =
    CALCULATE (
        MIN ( Table1[Date] ),
        FILTER ( Table1, Table1[ID] = EARLIER ( Table2[ID] ) )
    )
VAR _GROUPinOldestDate =
    CALCULATE (
        SELECTEDVALUE ( Table1[Group] ),
        FILTER (
            Table1,
            Table1[ID] = EARLIER ( Table2[ID] )
                && Table1[Date] = _Oldest_Date
        )
    )
VAR _Count_Group =
    CALCULATE (
        COUNT ( Table1[Group] ),
        FILTER (
            Table1,
            Table1[ID] = EARLIER ( Table2[ID] )
                && Table1[Group] = _GROUPinOldestDate
        )
    )
RETURN
    IF ( Table2[Change Group] > 1, _Count_Group, BLANK () )  

Result is as below.

RicoZhou_0-1665479162510.png

 

Best Regards,
Rico Zhou

 

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

6 REPLIES 6
tamerj1
Super User
Super User

Hi @Mentzer 
Please try

Count Changed =
SUMX ( VALUES ( Table1[ID] ), IF ( [Changed Group] > 1, 1 ) )

In the followin part, the Changed Group is not recognized:

IF ( [Changed Group] > 1, 1 )

 

Hi @Mentzer ,

 

Here I suggest you to try this code to create a calculated column.

Count Group in Oldest Date = 
VAR _Oldest_Date =
    CALCULATE (
        MIN ( Table1[Date] ),
        FILTER ( Table1, Table1[ID] = EARLIER ( Table2[ID] ) )
    )
VAR _GROUPinOldestDate =
    CALCULATE (
        SELECTEDVALUE ( Table1[Group] ),
        FILTER (
            Table1,
            Table1[ID] = EARLIER ( Table2[ID] )
                && Table1[Date] = _Oldest_Date
        )
    )
VAR _Count_Group =
    CALCULATE (
        COUNT ( Table1[Group] ),
        FILTER (
            Table1,
            Table1[ID] = EARLIER ( Table2[ID] )
                && Table1[Group] = _GROUPinOldestDate
        )
    )
RETURN
    IF ( Table2[Change Group] > 1, _Count_Group, BLANK () )  

Result is as below.

RicoZhou_0-1665479162510.png

 

Best Regards,
Rico Zhou

 

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

Hi @Mentzer 

Count Changed =
SUMX ( VALUES ( Table1[ID] ), IF ( DISTINCTCOUNT ( Table1[Groups] ) > 1, 1 ) )
parry2k
Super User
Super User

@Mentzer check this video on my YT channel and tweak it as you see fit How to get value of each product based on the most recent transaction - Power BI - YouTube

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop shop for Power BI-related projects/training/consultancy.

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Your solution is very good, sir. Thank you very much for the video.

But when performing the first formula with TOPN, it gives a memory error and it is not possible to perform the calculations. Is there any other solution?

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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