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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
RichOB
Post Partisan
Post Partisan

Table with every combination

Hi, using the table1, how do I get every combination like in table2 please?

 

Table1

SystemLocation
LaptopNewcastle
LaptopNewcastle
EmailNewcastle
ManchesterCRM
ManchesterCRM
ManchesterCRM


Table2

SystemLocationCount
LaptopNewcastle2
EmailNewcastle1
CRMNewcastle0
LaptopManchester0
EmailManchester0
CRMManchester3


Thanks

1 ACCEPTED SOLUTION
freginier
Super User
Super User

Hey there!

 

You can achieve the result in Power BI / DAX or SQL by generating every possible combination of System and Location, and then counting the occurrences.

 

Use the following DAX formula to create a new table in Power BI:

Table2 =
VAR Systems = VALUES(Table1[System])
VAR Locations = VALUES(Table1[Location])

RETURN
ADDCOLUMNS(
CROSSJOIN(Systems, Locations),
"Count", COUNTROWS(FILTER(Table1, Table1[System] = EARLIER([System]) && Table1[Location] = EARLIER([Location])))
)

What this does:

VALUES(Table1[System]) → Gets unique systems
VALUES(Table1[Location]) → Gets unique locations
CROSSJOIN() → Creates all possible combinations
COUNTROWS() → Counts occurrences of each pair

 

Hope this helps!

😁😁

View solution in original post

3 REPLIES 3
RichOB
Post Partisan
Post Partisan

Thanks for the solution and explanation!! 🙂

rajendraongole1
Super User
Super User

Hi @RichOB  - You can achieve this in Power BI using a cross join to get all possible combinations of System and Location, followed by a COUNTROWS measure to count occurrences. 

 

Table2 =
CROSSJOIN(
    DISTINCT( Tab1[System] ),
    DISTINCT( Tab1[Location] )
)
 

 

rajendraongole1_0-1740731404112.png

 

Count =
VAR sys = SELECTEDVALUE(Table2[System])
VAR loc = SELECTEDVALUE(Table2[Location])

VAR rowCount =
    CALCULATE(
        COUNTROWS(tab1),
        tab1[System] = sys,
        Tab1[Location] = loc
    )

RETURN
IF(ISBLANK(rowCount), 0, rowCount)
 
 
Please find the attached pbix file . hope thishelps.

 

 

 





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

Proud to be a Super User!





freginier
Super User
Super User

Hey there!

 

You can achieve the result in Power BI / DAX or SQL by generating every possible combination of System and Location, and then counting the occurrences.

 

Use the following DAX formula to create a new table in Power BI:

Table2 =
VAR Systems = VALUES(Table1[System])
VAR Locations = VALUES(Table1[Location])

RETURN
ADDCOLUMNS(
CROSSJOIN(Systems, Locations),
"Count", COUNTROWS(FILTER(Table1, Table1[System] = EARLIER([System]) && Table1[Location] = EARLIER([Location])))
)

What this does:

VALUES(Table1[System]) → Gets unique systems
VALUES(Table1[Location]) → Gets unique locations
CROSSJOIN() → Creates all possible combinations
COUNTROWS() → Counts occurrences of each pair

 

Hope this helps!

😁😁

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors