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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ravitejaballa
Helper III
Helper III

Count by Catagory

Hi,

 

I trying to get number of DeviceID for a each catagory (binLegendColumn).

But it has to be for latest value for a given timestamp.

As you can see below, i am able to fetch latest hours value (<= timestamp)

 

image.png

 

From this, expected output

binLegendnumber of distinct deviceid
< 0 Hours1
0 - 24 Hours2
25 - 100 Hours1
> 100 Hours1

 

my pbix file:

https://1drv.ms/u/s!AhI1WOiXwAe-qNl6FDPyeZvIv-Xzew?e=98X6Fa

 

Here is my sample data.

DeviceIDlastValueHoursbinLegendColumntimestamp
A-345< 0 Hours7/13/2020 0:00
A-150< 0 Hours7/12/2020 0:00
A00 - 24 Hours7/11/2020 0:00
A200 - 24 Hours7/10/2020 0:00
A5025 - 100 Hours7/9/2020 0:00
A200> 100 Hours7/8/2020 0:00
B10025 - 100 Hours7/12/2020 0:00
B7025 - 100 Hours7/11/2020 0:00
B240 - 24 Hours7/10/2020 0:00
B00 - 24 Hours7/9/2020 0:00
B-300< 0 Hours7/8/2020 0:00
C230 - 24 Hours7/13/2020 0:00
C00 - 24 Hours7/12/2020 0:00
C00 - 24 Hours7/11/2020 0:00
C-100< 0 Hours7/10/2020 0:00
C-250< 0 Hours7/9/2020 0:00
D200> 100 Hours7/12/2020 0:00
D10025 - 100 Hours7/11/2020 0:00
D200 - 24 Hours7/10/2020 0:00
D-5< 0 Hours7/9/2020 0:00
D-150< 0 Hours7/8/2020 0:00
E220 - 24 Hours7/12/2020 0:00
E50 - 24 Hours7/11/2020 0:00
E20 - 24 Hours7/10/2020 0:00
E-15< 0 Hours7/9/2020 0:00
E-25< 0 Hours7/8/2020 0:00

 

binbinLegend
1< 0 Hours
20 - 24 Hours
325 - 100 Hours
4> 100 Hours

 

 

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.  i have solve it using measures only.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

18 REPLIES 18
v-diye-msft
Community Support
Community Support

Hi @ravitejaballa 

 

If you've fixed the issue on your own please kindly share your solution. if the above posts help, please kindly mark it as a solution to help others find it more quickly. If not, please kindly elaborate more. thanks!

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
amitchandak
Super User
Super User

@ravitejaballa , You can try measures like

 

m1 =lastnonblankvalue(Table[timestamp],max(Table[binLegendColumn]))

 

m2 = lastnonblankvalue(Table[timestamp],max(Table[lastValueHours]))

@amitchandak 

Thanks for reply,

I already have these measure in my report.

image.png

 

 

 

 

 

 

 

 

Using this measure, i want to get count of number of deviceID for each legend.

Like below.

ravitejaballa_0-1594730502553.png

 

Hi @ravitejaballa ,

 

Based on your Data No of Distinct Device Id are as below.

 

 

1.jpg

 

2.JPG

 

In such case you can just use.

 

(DISTINCTCOUNT(deviceHours[DeviceID])

 

 

 

How did you get 1 , 2, 1, 1 .

 

Let me know if I am missing something.

 

Regards

Harsh Nathani

Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

 

 

@harshnathani 

Yes, you are missing one thing.

It has to be latest value for a given timestamp.

you can refer my sample file.

https://1drv.ms/u/s!AhI1WOiXwAe-qNl6FDPyeZvIv-Xzew?e=98X6Fa

 

ravitejaballa_0-1594743077434.png

 

 

Hi @ravitejaballa ,

 

 

Try this measure

 

TestMeasure = 
var a = CALCULATE(MAX(deviceHours[timestamp]),ALLSELECTED())
var b = CALCULATE(DISTINCTCOUNTNOBLANK(deviceHours[DeviceID]),FILTER(deviceHours,deviceHours[timestamp] =  a))

RETURN

b

 

1.jpg

 

 


Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

@harshnathani 

Thank for reply,

I think we are close to solution.

You solution work for timestamp (7/11/2020) as we have data on this day for all devices.

But as you can see from below for timestamp - 7/13/2020.

It failed, because for binLegend it took max date but we need to get last availabe date in the given range.

 

Excepted output:

ravitejaballa_1-1594816495593.png

 

 

ravitejaballa_0-1594816238705.png

 

Hi @ravitejaballa ,

 

Incase you want the last Available Date, just remove ALLSELECTED()

 

Regards,

Harsh Nathani

Appreciate with a Kudos!! (Click the Thumbs Up Button)

Did I answer your question? Mark my post as a solution!

Hi @ravitejaballa ,

 

 

Your filter context is BinLegend and you are looking for Last Date by Id ?

 

Do you want the last visible date by BinLegend  or By ID ?

 

Not sure if the slicer will work on this. Need to check.

 

1.jpg

 

This gives me the MAX Date of the BIN Legend, but you need the dates by ID ?

 

Not sure but can I know the business insights which this will give .  Just curious.

 

 

Regards,

Harsh Nathani

 

 

@harshnathani 

 

I need how many number of deviceIDs falls into each binLegend.

For a given timestamp range, we need to get latest/last avaiable value (LatestHours/binLegendMeasure).

and

count number of deviceIDs in each binLegend

 

ravitejaballa_0-1594821113775.png

 

@harshnathani @amitchandak 

 

Is there a way to generate below table and group by "binLegendMeasure" and get count of DeviceID  in measure?

 

ravitejaballa_0-1594823036867.png

 

@harshnathani @amitchandak 

Understood my requirement?

Is it possible in power bi ?

Hi,

You may download my PBI file from here.  i have solve it using measures only.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur

You are awesome!!

your measure worked for me.

Did small change to get latest available value in given time range.

TestMeasure = 
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            VALUES ( deviceHours[DeviceID] ),
            "ABCD", CALCULATE (
                [LatestHours],
                CALCULATETABLE ( VALUES ( deviceHours[DeviceID] ) ),
                ALLSELECTED ()
            )
        ),
        COUNTROWS (
            FILTER (
                binMater,
                [ABCD] >= binMater[Lower bin legend]
                    && [ABCD] <= binMater[Upper bin legend]
            )
        ) > 0
    )
)

 

 

 

ravitejaballa_0-1595175858287.png

 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

if a Power Query approach is accepted, here it is one:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZFLDoUgDEX3wlhiWyTq0A+rMO5/G88+CFKuI5LT5p7ecF1uc4PzYYrPM48cRiEhdw9lwJHyQOygULZUCiaLS8baL2e8vHh/ABMalc+oVCwTKPd632qhD6g8NCNA+ePtKJ+ULfX1bOoGgu3Ppn0bf7b1ud+HeMU+foXXb2uKJg0RcCqOYPwvgzDl6N6Yck0jvH8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DeviceID = _t, lastValueHours = _t, timestamp = _t]),
    #"Changed Type" = Table.Partition(Table.TransformColumnTypes(Source,{{"DeviceID", type text}, {"lastValueHours", Int64.Type}, {"timestamp", type date}}),"lastValueHours",4,each Number.From(_<0)*0+ Number.From(_>=0 and _<24)*1+Number.From(_>=24 and _<100)*2+Number.From(_>=100)*3),
    #"Converted to Table" = Table.FromList(#"Changed Type", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Index", 1, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "distDev", each List.Count(List.Distinct(_[Column1][DeviceID])))
in
    #"Added Custom"

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYopNTAwTlYwUPDILy0qVorViVYyAgobKOgqGJkgCRoDBY1MgaKGBshqTWBGpCJLxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [bin = _t, binLegend = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"bin", Int64.Type}, {"binLegend", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"bin"}, binned, {"Index"}, "binned", JoinKind.LeftOuter),
    #"Expanded binned" = Table.ExpandTableColumn(#"Merged Queries", "binned", {"distDev"}, {"binned.distDev"})
in
    #"Expanded binned"

 

 

this is the output got

 

image.png

 

 

if you want to change the destination of same value, adapt this expression accordingly:

 

= Table.Partition(Table.TransformColumnTypes(Source,{{"DeviceID", type text}, {"lastValueHours", Int64.Type}, {"timestamp", type date}}),"lastValueHours",4,each Number.From(_<0)*0+ Number.From(_>=0 and _<24)*1+Number.From(_>=24 and _<100)*2+Number.From(_>=100)*3)

 

 

 

@Anonymous 

Thanks for reply.

My case is dynamic with time range.

So measure is better option.

@harshnathani  Tried that but failed.

ravitejaballa_0-1594816798272.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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