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

DAX Expression to choose SSAS tabular model Measure based on Dimensional table selection.

I have desgined a tabular model cube in SSAS on transactionas. We have two facts one for transaction and one for offset transaction and there are multiple dimension tables. 

 

FACT_A - Transactions

TRN_FACT_ID,   POSTED_DATE,  TRN_AMT

1                      20221001         5000

2                      20221001         10000

 

FACT_B - Offset Transaction

OFFSET_FACT_ID,  TRN_FACT_ID,  Posted Date, TNR OFFSET Amt

234                        1                     20221001        3000

345                        1                     20221001         2000

456                         2                     20221001         10000

 

So we are not using FACT_B as a fact table in tabular model instead we are using it as a Dimensional table. But requirement is to get offset tran count as a measure. I did a count(*) and grouped tran_fact_id from FACT_B and left joined it to fact_a on TRN_FACT_ID  to bring in offset count and created a measure on it. 

 

Cube results(when only offset count is pulled with transaction)

TRN_FACT_ID,   POSTED_DATE,  TRN_AMT,   OFFSET COUNT

1                      20221001         5000                2

2                      20221001         10000              1

 

Cube results(If i pull in any attribute from Offset table)

TRN_FACT_ID,   POSTED_DATE,  TRN_AMT,  TNR OFFSET Amt, OFFSET COUNT

1                      20221001         5000                2000                 2

1                      20221001         5000                3000                 2

2                      20221001         10000              10000               1

 

Cube results(Expected results) (Offset count should be 1 on each line when an attribute is selected from offset table if not count should be 2)

TRN_FACT_ID,   POSTED_DATE,  TRN_AMT,  TNR OFFSET Amt, OFFSET COUNT

1                      20221001         5000                2000                 1

1                      20221001         5000                3000                 1

2                      20221001         10000              10000               1

 

 

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @hmed435 ,

 

Please try:

OFFSET COUNT = COUNT('FACT_B - Offset Transaction'[TNR OFFSET Amt])

Final output:

vjianbolimsft_0-1669187591608.png

Best Regards,

Jianbo Li

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

The Fact_B table is not used as a fact table in the cube tabular design instead it is used as a dimension table and added a relationship between Fact_A and Fact_B. I added count on Fact_B field but i am getting below results.

TRN_FACT_ID,   POSTED_DATE,  TRN_AMT,  TNR OFFSET Amt, OFFSET COUNT

1                      20221001         5000                2000                 3

1                      20221001         5000                3000                 3

2                      20221001         10000              10000               3

 

I am getting count as total number of rows in Fact_B table. not as per my selection. 

 

We ended up removing Offset count from the cube.

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.