Help with Compound Dataview Values

Topic : 2/2

Summary
  1. How to extract the Fund or ActionItem via the field Monitoring? (DQL01, DQL10, DVJS03, DVJS10)
  2. How to filter by Fund or ActionItem via the field Monitoring, such as “Monitoring:: FundQ | Do That0403”, from the Markdown files with the case_DVIF_DSS structure? (DQL10, DVJS03, DVJS10)
  3. How to transform the DQL10 query into a DVJS code with the FLATTEN methods step by step? (DVJS10, 【DQL10 > Notes > Q2】)
  4. How to filter and sort an AoH(an Array of JavaScript Objects) and render a table via a DVJS code? (DVJS01)

NOTE:

  1. The DVJS01 can help you to figure out the basic DVJS code.
  2. The DVJS10 performs the same operations as the DQL10 with the FLATTEN methods step by step.
  3. The DVJS10 can help you to figure out the DQL10, including how to use the FLATTEN operator.

DQL10_split_up_a_list_into_each_individual_element_via_FLATTEN_and_filter_and_TABLE

NOTE: THE OLD NAME = DQL50_alias_new_field_by_flatten

Summary
  • added on 2022-07-16
  • updated on 2022-09-07
    • Added the following expression.
    ```dataview
    WHERE OneMonitoring
    ```
    
  • updated on 2023-03-10
    • Added the【DQL10 > Notes > Q2】.

Main DQL

Code Name Data type Purposes Remark
DQL10
split_up_a_list
into_each_individual_element
_via_FLATTEN
_and_filter
_and_TABLE
Monitoring:
1.a string
2.a list of strings

OneMonitoring:
a string
1.“Monitoring:: FundQ | Do That0403”
1.To filter by Monitoring
2.To sort by file.name in ascending order
3.To split up a list Monitoring into each individual element OneMonitoring

4.To filter by OneMonitoring
5.To define a new field variable Fund
6.To define a new field variable ActionItem
7.To filter by Fund and ActionItem
8.To display the result as a table
Note:
Require the files with the case_DVIF_DSS structure


Features:
1.easier to read
2.easier to modify

Notes

Summary

Q1: What does the following DQL statement mean?

Summary_Q1
Original Example: Q1 (To be explained)
```dataview

FLATTEN Monitoring AS OneMonitoring


WHERE OneMonitoring 
FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem

```

A1_11:

```dataview

// To split up a list `Monitoring` into each individual element `OneMonitoring`
// 1.`Monitoring`: a string or a list of string
// 2.`OneMonitoring`: a string
FLATTEN Monitoring AS OneMonitoring


WHERE OneMonitoring 


// To define a field variable `Fund` as the expression `split(F_Monitoring, "\s+\|\s+")[0]`
FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund


// To define a field variable `ActionItem` as the expression `split(F_Monitoring, "\s+\|\s+")[1]`
FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem

```

Q2: How to explain the meaning of the DQL10 with the DVJS10 code?

Summary_Q2
Original Example: Q2 (To be explained)
```dataview
TABLE WITHOUT ID
      file.link AS "File",
      OneMonitoring AS "Monitoring",
      Fund AS "Fund",
      ActionItem AS "Action Item"
FROM "100_Project/02_dataview/Q06_Monitoring/Q06_test_data"
WHERE Monitoring != null       
SORT file.name ASC


FLATTEN Monitoring AS OneMonitoring


WHERE OneMonitoring
FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem
WHERE contains(Fund, "FundQ") AND contains(ActionItem, "That")
```

A2_21:

```dataview
// T91. output pages: TABLE
// TABLE WITHOUT ID
//       file.link AS "File",
//       OneMonitoring AS "Monitoring",
//       Fund AS "Fund",
//       ActionItem AS "Action Item"
// #####################################################################
// dv.table(
//     ["File", "Monitoring", "Fund", "Action Item"],
//     pages.map((page) => [
//         page.file.link,
//         page.OneMonitoring,
//         page.Fund,
//         page.ActionItem,
//     ])
// );
TABLE WITHOUT ID
      file.link AS "File",
      OneMonitoring AS "Monitoring",
      Fund AS "Fund",
      ActionItem AS "Action Item"


// T11. define pages: get pages from Sources
// FROM "100_Project/02_dataview/Q06_Monitoring/Q06_test_data"
// #####################################################################
// let pages = dv.pages('"100_Project/02_dataview/Q06_Monitoring/Q06_test_data"');
FROM "100_Project/02_dataview/Q06_Monitoring/Q06_test_data"


// T13. filter by Monitoring
// WHERE Monitoring != null 
// #####################################################################
// pages = pages.where(
//     (page) => page.Monitoring !== null && page.Monitoring !== undefined
// );
WHERE Monitoring != null


// T15. sort by file.name: 
// SORT file.name ASC
// #####################################################################
// pages = pages.sort((page) => page.file.name, "asc");
SORT file.name ASC


// T20. Transform page.Monitoring into a Dataview Data array:
// original page.Monitoring : a string or a list of strings
// #####################################################################
// pages.forEach((page) => {
//     page.Monitoring = dv.array(page.Monitoring);  
// });
//
// T21. To spilt up a list `Monitoring` into each individual element `OneMonitoring`
// update pages: add a new field `OneMonitoring` into each page
// FLATTEN Monitoring AS OneMonitoring
// #####################################################################
// pages = pages.flatMap((page) =>
//     page.Monitoring.map((e) => Object.assign({}, page, { OneMonitoring: e }))
// );
FLATTEN Monitoring AS OneMonitoring


// T31. filter by OneMonitoring
// WHERE OneMonitoring 
// #####################################################################
// pages = pages.where((page) => page.OneMonitoring);
WHERE OneMonitoring


// T33. update pages:
// update pages: add a new field `Fund` into each page
// update pages: add a new field `ActionItem` into each page
// FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
// FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem
// #####################################################################
// pages.forEach((page) => {
//     page.Fund  = page.OneMonitoring.split(/\s+\|\s+/)[0];
//     page.ActionItem = page.OneMonitoring.split(/\s+\|\s+/)[1];
// });
FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem


// T35. filter by Fund and ActionItem
// update pages: add a new field `Fund` into each page
// WHERE contains(Fund, "FundQ") AND contains(ActionItem, "That")
// #####################################################################
// pages = pages.where(
//     (page) =>
//         dv.func.contains(page.Fund, "FundQ") &&
//         dv.func.contains(page.ActionItem, "That")
// );
WHERE contains(Fund, "FundQ") AND contains(ActionItem, "That")
```

Code DQL10_split_up_a_list_into_each_individual_element_via_FLATTEN_and_filter_and_TABLE

NOTE: OLD NAME = DQL50_alias_new_field_by_flatten

Summary_code
title: DQL10_split_up_a_list_into_each_individual_element_via_FLATTEN_and_filter_and_TABLE =>0.Require the files with the `case_DVIF_DSS` structure 1.To filter by `Monitoring` 2.To sort by `file.name` in ascending order 3.To split up a list `Monitoring` into each individual element `OneMonitoring` 4.To filter by `OneMonitoring` 5.To define a new field variable `Fund` 6.To define a new field variable `ActionItem` 7.To filter by `Fund` and `ActionItem` 8.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      file.link AS "File",
      OneMonitoring AS "Monitoring",
      Fund AS "Fund",
      ActionItem AS "Action Item"
FROM "100_Project/02_dataview/Q06_Monitoring/Q06_test_data"
WHERE Monitoring != null       
SORT file.name ASC


FLATTEN Monitoring AS OneMonitoring


WHERE OneMonitoring 
FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem
WHERE contains(Fund, "FundQ") AND contains(ActionItem, "That")
```

Screenshots(DQL10)


DVJS10_split_up_a_list_into_each_individual_element_via_FLATTEN_and_filter_and_TABLE

Purposes:

  1. The DVJS10 performs the same operations as the DQL10 with the FLATTEN methods step by step.
  2. The DVJS10 can help you to figure out the DQL10, including how to use the FLATTEN operator.
Summary

Main DVJS

Code Name Data type Purposes Remark
DVJS10
split_up_a_list
into_each_individual_element
_via_FLATTEN
_and_filter
_and_TABLE
Monitoring:
1.a string
2.a list of strings

OneMonitoring:
a string
1.“Monitoring:: FundQ | Do That0403”
1.The DVJS10 performs the same operations as the DQL10 with the FLATTEN methods step by step.
2.The DVJS10 can help you to figure out the DQL10, including how to use the FLATTEN operator.
Note:
1.Require the files with the case_DVIF_DSS structure

2.the DQL10 = the DVJS10

Notes:

Summary

Q1: How to use the mutate function instead of the forEach function with the DVJS10? (T20 and T33)

Summary_Q1
Original Example: Q1 (To be modified)
```dataviewjs
// T20. Transform page.Monitoring into a Dataview Data array:
// original page.Monitoring : a string or a list of strings
// #####################################################################
pages.forEach((page) => {
    page.Monitoring = dv.array(page.Monitoring);  
});


// T21. To spilt up a list `Monitoring` into each individual element `OneMonitoring`
// #####################################################################


// T31. filter by OneMonitoring
// #####################################################################


// T33. update pages:
// update pages: add a new field `Fund` into each page
// update pages: add a new field `ActionItem` into each page
// FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
// FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem
// #####################################################################
pages.forEach((page) => {
    page.Fund  = page.OneMonitoring.split(/\s+\|\s+/)[0];
    page.ActionItem = page.OneMonitoring.split(/\s+\|\s+/)[1];
});



```

A1_11:

Another Example: A1_11
Summary_A1_11
```dataviewjs
// T20. Transform page.Monitoring into a Dataview Data array:
// original page.Monitoring : a string or a list of strings
// #####################################################################
// pages.forEach((page) => {
//     page.Monitoring = dv.array(page.Monitoring);  
// });
pages = pages.mutate((page) => {
    page.Monitoring = dv.array(page.Monitoring);
});


// T21. To spilt up a list `Monitoring` into each individual element `OneMonitoring`
// #####################################################################


// T31. filter by OneMonitoring
// #####################################################################


// T33. update pages:
// update pages: add a new field `Fund` into each page
// update pages: add a new field `ActionItem` into each page
// FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
// FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem
// #####################################################################
// pages.forEach((page) => {
//     page.Fund  = page.OneMonitoring.split(/\s+\|\s+/)[0];
//     page.ActionItem = page.OneMonitoring.split(/\s+\|\s+/)[1];
// });
pages = pages.mutate((page) => {
    page.Fund = page.OneMonitoring.split(/\s+\|\s+/)[0];
    page.ActionItem = page.OneMonitoring.split(/\s+\|\s+/)[1];
});
```

Q2: How to use the mutate function to simplify the DVJS10?

Summary_Q2

A2_21:

Another Example: A2_21
Summary_A2_21
```dataviewjs
// T11. define pages: get pages from Sources
// T13. filter by Monitoring
// T15. sort by file.name:
// T20. Transform page.Monitoring into a Dataview Data array:
// #####################################################################
let pages = dv
    .pages('"100_Project/02_dataview/Q06_Monitoring/Q06_test_data"')
    .where((page) => page.Monitoring !== null && page.Monitoring !== undefined)
    .sort((page) => page.file.name, "asc")
    .mutate((page) => {
        page.Monitoring = dv.array(page.Monitoring);
    });


// T21. To spilt up a list `Monitoring` into each individual element `OneMonitoring`
// update pages: add a new field `OneMonitoring` into each page
// FLATTEN Monitoring AS OneMonitoring
// #####################################################################
pages = pages.flatMap((page) =>
    page.Monitoring.map((e) => Object.assign({}, page, { OneMonitoring: e }))
);


// T31. filter by OneMonitoring
// T33. update pages:
// update pages: add a new field `Fund` into each page
// update pages: add a new field `ActionItem` into each page
// WHERE OneMonitoring
// T35. filter by Fund and ActionItem
// #####################################################################
pages = pages
    .where((page) => page.OneMonitoring)
    .mutate((page) => {
        page.Fund = page.OneMonitoring.split(/\s+\|\s+/)[0];
        page.ActionItem = page.OneMonitoring.split(/\s+\|\s+/)[1];
    })
    .where(
        (page) =>
            dv.func.contains(page.Fund, "FundQ") &&
            dv.func.contains(page.ActionItem, "That")
    );


// T91. output pages: TABLE
// TABLE WITHOUT ID
//       file.link AS "File",
//       OneMonitoring AS "Monitoring",
//       Fund AS "Fund",
//       ActionItem AS "Action Item"
// #####################################################################
dv.table(
    ["File", "Monitoring", "Fund", "Action Item"],
    pages.map((page) => [
        page.file.link,
        page.OneMonitoring,
        page.Fund,
        page.ActionItem,
    ])
);

```

Code DVJS10_split_up_a_list_into_each_individual_element_via_FLATTEN_and_filter_and_TABLE

Summary_code
title: DVJS10_split_up_a_list_into_each_individual_element_via_FLATTEN_and_filter_and_TABLE  =>1.The DVJS10 performs the same operations as the DQL10 with the FLATTEN methods step by step. 2.The DVJS10 can help you to figure out the DQL10, including how to use the FLATTEN operator.
collapse: close
icon: 
color: 
```dataviewjs
// T11. define pages: get pages from Sources
// FROM "100_Project/02_dataview/Q06_Monitoring/Q06_test_data"
// #####################################################################
let pages = dv.pages('"100_Project/02_dataview/Q06_Monitoring/Q06_test_data"');


// T13. filter by Monitoring
// WHERE Monitoring != null 
// #####################################################################
pages = pages.where(
    (page) => page.Monitoring !== null && page.Monitoring !== undefined
);


// T15. sort by file.name: 
// SORT file.name ASC
// #####################################################################
pages = pages.sort((page) => page.file.name, "asc");


// T20. Transform page.Monitoring into a Dataview Data array:
// original page.Monitoring : a string or a list of strings
// #####################################################################
pages.forEach((page) => {
    page.Monitoring = dv.array(page.Monitoring);  
});


// T21. To spilt up a list `Monitoring` into each individual element `OneMonitoring`
// update pages: add a new field `OneMonitoring` into each page
// FLATTEN Monitoring AS OneMonitoring
// #####################################################################
pages = pages.flatMap((page) =>
    page.Monitoring.map((e) => Object.assign({}, page, { OneMonitoring: e }))
);


// T31. filter by OneMonitoring
// WHERE OneMonitoring
// #####################################################################
pages = pages.where((page) => page.OneMonitoring);


// T33. update pages:
// update pages: add a new field `Fund` into each page
// update pages: add a new field `ActionItem` into each page
// FLATTEN split(OneMonitoring, "\s+\|\s+")[0] AS Fund
// FLATTEN split(OneMonitoring, "\s+\|\s+")[1] AS ActionItem
// #####################################################################
pages.forEach((page) => {
    page.Fund  = page.OneMonitoring.split(/\s+\|\s+/)[0];
    page.ActionItem = page.OneMonitoring.split(/\s+\|\s+/)[1];
});


// T35. filter by Fund and ActionItem
// update pages: add a new field `Fund` into each page
// WHERE contains(Fund, "FundQ") AND contains(ActionItem, "That")
// #####################################################################
pages = pages.where(
    (page) =>
        dv.func.contains(page.Fund, "FundQ") &&
        dv.func.contains(page.ActionItem, "That")
);


// T91. output pages: TABLE
// TABLE WITHOUT ID
//       file.link AS "File",
//       OneMonitoring AS "Monitoring",
//       Fund AS "Fund",
//       ActionItem AS "Action Item"
// #####################################################################
dv.table(
    ["File", "Monitoring", "Fund", "Action Item"],
    pages.map((page) => [
        page.file.link,
        page.OneMonitoring,
        page.Fund,
        page.ActionItem,
    ])
);


```

Screenshots(DVJS10):


2 Likes