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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
anesbbs
Frequent Visitor

Questions related with context

Hi, I'm new to Power BI.

I have dimCust table as follow:

| CustID | CustName | CustAge | CustLoc |

1A24X
2B22Y
3C32X
4D16X
5E54Z
6F32Z
7G27Y
8H43X
9I33Y
10J25Z
11K42Y
12L51X

 

And Sales table as follow:

| SalesID | CustID | Date | ProductID | Qty |

1401 April 202312
2302 February 202332
3413 February 202324
4514 January 202343
5213 April 2023612
6218 March 202333
7621 February 202325
8519 January 202336
9317 April 202343
10209 March 2023510
11622 March 202364
12717 February 2023410
13619 February 202339
14628 March 202327
15421 January 202312

 

The relationship is as follow:

 

anesbbs_1-1684460533020.png

 

I then created a measure table consists of several measures as follow:

  1. VisitQty = COUNT('Sales'[SalesID])
  2. EarliestVisit = MINX(Sales, [Date])
  3. LatestVisit = MAXX(Sales, [Date])
  4. PeriodDay = DATEDIFF([EarliestVisit], [LatestVisit], DAY)
  5. TotalPeriod = CALCULATE([PeriodDay], ALLSELECTED('dimCust'[CustID]))
  6. TotalVisit = CALCULATE(COUNT('Sales'[SalesID]), ALLSELECTED('dimCust'[CustID]))
  7. Visit/Period = DIVIDE([TotalVisit], [TotalPeriod])

Then in the report view, I chose Table Visualization and filled it with columns and measures:

  • CustID taken from dimCust table
  • Other columns are from the above measures

anesbbs_8-1684461035022.png

 

 

When I excluded CustName column as the above, the last 3 columns consist of fix total value for each column in all rows (red box), as I wanted it.

 

And as I filtered the CustLoc using slicer, the total values will also be adjusted and each row will still be filled with the fix total value as follows:

anesbbs_9-1684461121006.png

 

 

But when I included the CustName column, it filters the CustID column and the values in last 3 columns become only for the particular rows, as follows:

 

anesbbs_7-1684460925823.png

 

One more thing, I added other measure and included it in the table:

  1. VV = DIVIDE(([VisitQty] - [Visit/Period]*[PeriodDay])^2, [PeriodDay])

The result for each row is correct, but the total value become zero, as follows:

anesbbs_5-1684460809881.png

 

I have 3 questions:

1. How to show all CustID after add CustName column?

2. How to keep fix total value in each row based on slicer filter after add CustName column?

3. How to show correct total value for VV column?

 

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @anesbbs ,

 

I suggest you to try code as below.

TotalPeriod = CALCULATE([PeriodDay], ALLSELECTED('dimCust'[CustID]),REMOVEFILTERS(dimCust[CustName]))
TotalVisit = CALCULATE(COUNT('Sales'[SalesID]),  ALLSELECTED('dimCust'[CustID]),REMOVEFILTERS(dimCust[CustName]))
VV Total = IF(HASONEVALUE(dimCust[CustID]),[VV],SUMX(VALUES(dimCust[CustID]),[VV]) )

Result is as below.

veqinmsft_0-1684748873213.pngveqinmsft_1-1684748883695.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

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hi @anesbbs ,

 

I suggest you to try code as below.

TotalPeriod = CALCULATE([PeriodDay], ALLSELECTED('dimCust'[CustID]),REMOVEFILTERS(dimCust[CustName]))
TotalVisit = CALCULATE(COUNT('Sales'[SalesID]),  ALLSELECTED('dimCust'[CustID]),REMOVEFILTERS(dimCust[CustName]))
VV Total = IF(HASONEVALUE(dimCust[CustID]),[VV],SUMX(VALUES(dimCust[CustID]),[VV]) )

Result is as below.

veqinmsft_0-1684748873213.pngveqinmsft_1-1684748883695.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.

 

 

@v-eqin-msft,

There is another question that I need your help, still with the same case.

 

I added another column to show current date in all rows.

Tried using formula as per your suggestion, but not working: 

CurrDate = CALCULATE(NOW(),  ALLSELECTED('dimCust'[CustID]),REMOVEFILTERS(dimCust[CustName]))

 

Would you please help again on this one?

 

 

lbendlin
Super User
Super User


Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

This is the outcome that I need:

CustIDCustNameVisitQtyEarliestVisitLatestVisitPeriodDayTotal PeriodTotalVisitVisit/PeriodVV
1A        
2B309 March 202313 April 20233593150.1610.20
3C202 February 202317 April 20237493150.1611.33
4D321 January 202301 April 20237093150.1610.98
5E214 January 202319 January 2023593150.1610.28
6F419 February 202328 March 20233793150.1610.10
7G117 February 202317 February 202309315  
8H        
9I        
10J        
11K        
12L        
  1514 January 202317 April 202393   2.91

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.