siufai6 / TIL

0 stars 0 forks source link

Using Power BI #7

Open siufai6 opened 9 months ago

siufai6 commented 9 months ago

always always remember power BI works with relational table structure (2/13/2024)

If you have data in the form of a complex header (e.g. city, and then product category as column headers), image

Power BI cannot use this form of data straight away. you need to convert it into a relational table. like below: image

To do this.. you transpose the original data so city and category becomes columns (fields in a table). And then unpivot the year data so that it becomes a de-normalized table ... so columns becomes city, category, year, value.

siufai6 commented 9 months ago

Adding Constant lines to Scatter chart in power BI

In visualization pane, click "add further analysis to your visual". x-axis and y-axis. click on fx to add average of PL and average of Duration. Then we have the constant lines in scatter chart.

image

siufai6 commented 9 months ago

Date dimension

table is a popular pattern in power BI. Basically it's a date dimension (image it as a decode table) that contains ALL dates ! To create... in table view.. add column then there is a DAX formula to create. To allow to create charts like seasonality chart, you can create additional columns like month only (or week only). Then you link it to your FACT table (data table). When creating a viz, drag the date you want (e.g. seasonality chart i just drag the month).. then add e.g. PL (sum, average..etc). Then you created a seasonality chart.

You can have many date columns in one table link to this date dimension table (imagine : stock purchase date, stock sell date).

When you create a visualization.. which one is it using?? the purchase date or the sell date?? it's the "active" relationship one.. I dunno.. may be it's not very useful if you need multiple charts one with purchase date and one with sell date??

siufai6 commented 9 months ago

Summarizing data on power BI.

I have a table named trades with these cols: code and pl. I would like to summarize average gain and average loss.

  1. Add a new measure of average of pl
  2. Add another measure ("avg loss") that average when pl is <0 like below CALCULATE ( [avg PL], KEEPFILTERS ( FILTER ( ALL (trades[PL] ), trades[PL] <0 ) ) )
  3. do the same for pl >=0 name it "avg gain"
  4. create a table viisualization and add code, "avg gain", "avg loss" to the table.
  5. Then you have a table with code and the respective average gain/loss. image
siufai6 commented 9 months ago

Summarize (and why to avoid it)

siufai6 commented 9 months ago

DAX calculated columns and Power Query computed columns (M expression)

siufai6 commented 9 months ago

Show tooltip that contains a visual

  1. create a new page, under format, select page type as tooltip image
  2. choose the field that should show when hover over (e.g. the original chart has sales amount bar, then we choose sales amount)
  3. create a visual on the page e.g. a sales trend chart.
  4. Go back to original page, in the visual, choose Format, and select Properties -> under tooltips and select the page we created in step 3. image
siufai6 commented 9 months ago

Terms