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
Debbie_Montique
Frequent Visitor

Countrows from Distinctcount from another column

Hi All,

 

I'm trying to do a count of all values from one column... got that, not a problem.  The problem is that I need my new count based on a distinct count from another column.  For example column A is sales orders, and column B is B2B or B2C values......some sales orders have multiple lines, I need to count how many rows are B2B and how many rows are B2C, but need the disntinct count of the sales orders (can't have the B2B count multiple rows.

 

I'm using B2B Count = IF(FIND("B2B",SalesOrder[B2B/B2C],1,-1) = -1,0,1) to count all my B2B, but it's counting *ALL* rows, and many sales orders have multiple lines.  I'm not sure how to make the distinct count from the sales order column query with my B2B Count.

 

Thanks for any help!

1 ACCEPTED SOLUTION

@Debbie_Montique

 

Good to know that you can solve your question.

 

Please accept the solution to others con use you.

 

 




Lima - Peru

View solution in original post

8 REPLIES 8
Vvelarde
Community Champion
Community Champion

@Debbie_Montique

 

Hi, a few ways to obtain:

 

Alternative 1:

 

Imng2.png

 

Alternative 2. Using a Measure:

 

Measure =
CALCULATE ( DISTINCTCOUNT ( Table1[SalesOrder] ) )

 Add a Visual and use B2B/B2C Column and the measure

 

Regards

 

Victor




Lima - Peru

Victor, thank you very much!  That works, but now I am stuck to figure out how to make a cost calculation.  B2B = $2.50 ea, and B2C = $1.65 ea.  I'm not sure how to get that in there.  I have a calculated column with the value (price) for each, but not sure how to make it multiply by only B2B and distinct # of orders, and B2C??

@Debbie_Montique

 

Can you post a sample of the data to replicate it.

Regards

VIctor




Lima - Peru

Hello,

 

Below is the data, please note that for each distinct SO Document that is B2B - price is $2.50, and for each distinct SO Document that is B2C - price is $1.65.

 

S.O.DocumentB2B/B2C
36094812B2B
36150140B2B
36211362B2B
36037098B2C
36094813B2C
36113575B2C
36132013B2C
36150156B2C
36189237B2C
36049426B2B
36066981B2B
36096529B2B
36159728B2B
36159733B2B
36170533B2B
36211343B2B
36244071B2C
36245048B2B
36034609B2B
36043892B2B
36045997B2B
36046243B2C
36046444B2B
36071046B2B
36170505B2B
35979970B2B
36008473B2B
36032993B2B
36035768B2B
36036393B2B
36044494B2B
36045814B2B
36046268B2B
36049434B2B
36049435B2B
36056082B2B
36056085B2B
36058503B2B
36058504B2B
36058513B2B
36058515B2B
36058516B2B
36058517B2B
36058518B2B
36058519

B2B

 

Here in my table I have the # of distinct orders by B2B/B2C as you suggested above, but I cannot multiply out the price per # of distinct orders:

 

Capture.JPG

 

Thank you very much!

 

@Debbie_Montique

 

Try with this measure:

 

Price =
IF (
    SELECTEDVALUE ( Table1[B2B/B2C] ) = "B2B";
    DISTINCTCOUNT ( Table1[S.O.Document] ) * 2,5;
    DISTINCTCOUNT ( Table1[S.O.Document] ) * 1,65
)

 

You can made dinamically replacing the HardCoded Price with the AVG of the calculated column.

 

Regards

 

Victor 




Lima - Peru

Victor, you are my HERO!!!  That works PERFECTLY.  I cannot thank you enough.  THANK YOU THANK YOU!!!

@Debbie_Montique

 

Good to know that you can solve your question.

 

Please accept the solution to others con use you.

 

 




Lima - Peru

But I'm going to need the counts of distinct B2B and B2C to do invoicing, and I cannot pull that from a Visual can I?

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.